If the prisoner is not entitled to his discharge, and is not bailed, the court or judge shall place him under the restraint from which he was taken, if the person under whose restraint he was is legally entitled thereto. If not so entitled, the court or judge shall commit the prisoner to the custody of such officer or person as by law is entitled thereto.
MCL 600.4361