Prisoner may be ordered to custody of proper officer In cases where 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. ?? 32-22-23.