If no legal cause is shown for the imprisonment or restraint, or for the continuation thereof, the court or judge shall discharge such party from the custody or restraint under which the person is held.