When a defendant in a criminal action, any time prior to pronouncement of sentence, is committed to the state hospital, the expenses of transporting him to and from the hospital and of maintaining him while confined therein shall be a charge against the county in which the indictment was found or information filed, but the county may recover such expenses from the estate of the defendant or from a relative, town, city or county required by law to provide for and maintain the defendant.