If no legal cause be shown for such imprisonment or restraint or for the continuance thereof the court or judge shall make a final order discharging such party from the custody or restraint.