The court or judge must make a final order to remand the prisoner if it shall appear that the prisoner is detained in custody either:
(1) By virtue of process issued by any court or judge of the United States, in a case where such court or judge has exclusive jurisdiction; or (2) By virtue of the final judgment or order of any competent court of civil or criminal jurisdiction or of any execution issued upon such judgment or order; or (3) For any contempt, specially and plainly charged in the commitment by some court, officer or body having authority to commit for the contempt so charged; and (4) That the time during which such party may be legally detained has not expired.