If it appears on the return of the writ that the prisoner is in custody by virtue of an order or civil process of a court legally constituted, or issued by an officer in the course of judicial proceedings before the officer, authorized by law, the prisoner shall be discharged or granted any other appropriate remedy in any of the following cases:
(1) when the jurisdiction of the court or officer has been exceeded, either as to matter, place, sum, or person;
(2) when, though the original imprisonment was lawful, yet by some act, omission, or event that has taken place afterwards, the party has become entitled to a discharge or other remedy;
(3) when the order or process is defective in some matter of substance required by law, rendering the process void;
(4) when the order or process, though in proper form, has been issued in a case not allowed by law;
(5) when the person having the custody of the prisoner under the order or process is not the person empowered by law to detain the prisoner; or
(6) when the order or process is not authorized by a judgment of a court or by a provision of law.