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