Counties containing more than fifty thousand inhabitants shall, and counties containing a lesser number of inhabitants may, provide and maintain at public expense, a detention room or house of detention, separated or removed from any jail, or police station, to be in charge of a matron, or other person of good character, wherein all children within the provisions of this chapter shall, when necessary, be sheltered.