It shall be the duty of the court or judge forthwith to remand the prisoner if it shall appear that he or she is held in custody, either:
(1) By virtue of any process issued by any court or judge of the United States in a cause where the court or judge has exclusive jurisdiction;
(2) By virtue of the final judgment or decree of any competent court of civil or criminal jurisdiction;
(3) For any contempt especially and plainly charged in the commitment by some court, judge, or body politic having authority by law to commit for contempt so charged; and
(4) Where the time during which the party may be legally detained has not expired.