The judge shall immediately send the petitioner back to the detaining authority if it appears that the petitioner is detained in custody:
(1) under process issued by a court or judge of the United States, in a case where the court or judge has exclusive jurisdiction;
(2) under final judgment of a competent court of civil or criminal jurisdiction, or under an execution issued upon a judgment of either of those courts; or
(3) for contempt of court, specially and plainly charged in the commitment, by a court having authority to commit for the contempt so charged.
The judge shall also immediately send the petitioner back to the detaining authority if it appears that the time during which the person may be legally detained has not expired.