If no legal cause is shown for such imprisonment or restraint, or for the continuance thereof, the court or judge shall discharge the party from the custody or restraint under which he is held. But if it appears on the return to the writ that the party is in custody by virtue of civil process from any court legally constituted, or issued by any officer in the course of judicial proceedings before him, authorized by law, such party can be discharged only in one of the following cases:
(1) Where the jurisdiction of such court or officer has been exceeded, either as to matter, place, sum or person.
(2) Where, though the original imprisonment was lawful, yet by some act, omission or event, which has taken place afterwards, the party has become entitled to be discharged.
(3) Where the process is defective in some matter of substance required by law, rendering such process void.
(4) Where the process, though in proper form, has been issued in a case not allowed by law.
(5) Where the person, having the custody of the party under such process, is not the person empowered by law to detain him.
(6) Where the process is not authorized by any judgment, order or decree of any court, nor by any provision of law. (1868-9, c. 116, s. 20; Code, s. 1645; Rev., s. 1847; C.S., s. 2235.)