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