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