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