No person who has been discharged by the order of a court upon habeas corpus shall again be imprisoned, restrained, or kept in custody for the same cause except in the following cases:
(1) if the party has been discharged from a commitment on a criminal charge and is afterwards committed for the same offense by legal order or process;
(2) if, after a judgment or discharge for a defect of evidence, or for a material defect in the commitment, in a criminal case, the party is again arrested on sufficient evidence and committed by legal process for the same offense;
(3) if, after a civil action, the party has been discharged for any illegality in the judgment, decree, or process specified in AS 12.75.100, and is afterwards imprisoned for the same cause of action;
(4) if, in a civil action, the party has been discharged from commitment on an order of arrest, and is afterwards committed on execution, in the same action, or on order of arrest in another action, after the dismissal of the first action.