In cases where any party is held under illegal restraint or custody, or any other person is entitled to the restraint or custody of such party, the Judge or Court may order such party to be committed to the restraint or custody of such person as is by law entitled thereto.
Ca. Pen. Code § 1493