It shall be the duty of all sheriffs as jailors to receive and safely keep, until discharged by due course of law, all prisoners arrested or committed under legal process from the officers of the courts of the United States, if the officer or person delivering such prisoner shall secure to the sheriff as jailor the amount of subsistence, bedding, fuel, clothing, medicine and medical fees allowed by law in such cases. No sheriff as jailor shall receive or keep any such prisoner where the receiving or keeping of such prisoner would tax the capacity of the jail in his county to the extent that there would not be sufficient room in said jail to safely keep and care for state and county prisoners in his custody or where the receiving or keeping of said prisoner would render such jail unduly unsanitary or dangerous to the health of the prisoners confined therein.