In all cases where the imprisonment is for a criminal, or supposed criminal matter, if it appears to the court that there is sufficient legal cause for the commitment of the prisoner, although such commitment may have been informally made, or without due authority, or the process may have been executed by a person not duly authorized, the court shall make a new commitment in proper form, and direct it to the proper officer, or admit the party to pretrial release if the case is eligible for pretrial release . The court shall also, when necessary, take the recognizance of all material witnesses against the prisoner, as in other cases. The recognizances shall be in the form provided by law, and returned as other recognizances. If any judge shall neglect or refuse to bind any such prisoner or witness by recognizance, or to return a recognizance when taken as hereinabove stated, he or she shall be guilty of a Class A misdemeanor in office, and be proceeded against accordingly.
735 ILCS 5/10-125