In all counties in Illinois wherein there may be situated a State penal or charitable institution, the State shall assume and pay to such county the necessary expenses incurred by it, and its officers, either by means of service rendered or otherwise, by reason of court proceedings therein involving a petition for relief by habeas corpus, by or on behalf of, an inmate of such institution who was not a resident of such county at the time of his commitment and was not committed by any court therein.
55 ILCS 50/1