In cases in which any party is held under illegal restraint or custody, and any other person is entitled to the custody or restraint of such party, the court may order such party to be committed to the custody or restraint of such person as by law is entitled thereto.
N.D.C.C. § 32-22-22