Section 23. If no legal cause is shown for the imprisonment or restraint, the court or justice shall discharge the prisoner.