Upon a hearing on a writ of habeas corpus, if no legal cause for the imprisonment or restraint of a party is shown, he must be discharged; but, if it appears that he is held or detained in custody by virtue of process issued by a court or judge of the United States in a case of which such court or judge has exclusive jurisdiction or by virtue of any legal engagement or enlistment in the army or navy of the United States or, being subject to the rules and articles of war is confined by anyone legally acting by authority thereof, or is in custody for any public offense committed in any other state or territory for which, by the Constitution and laws of the United States, he should be delivered up to the authority of such state or territory or that he is otherwise legally detained, he must be remanded.
Ala. Code § 15-21-21 (1975)