Section 29. A sheriff, jailer, superintendent of a house of correction or officer of a correctional institution who, under any pretence, gives, sells or delivers or knowingly permits to be given, sold or delivered to a prisoner in his custody any alcoholic beverages, as defined in section one of chapter one hundred and thirty-eight, or cider, unless the physician of the penal institution certifies in writing that the health of the prisoner requires the same; or such sheriff, jailer, superintendent of a house of correction or officer of a correctional institution who willingly or negligently suffers such prisoner to have or drink any alcoholic beverages, as so defined, or who places or keeps together prisoners in his custody of different sexes or classes, contrary to section twenty-two of chapter one hundred and twenty-seven, shall forfeit twenty-five dollars for the first offence and fifty dollars for any offence committed subsequent to the first conviction, and, upon such second conviction, shall be removed from office, and be ineligible to hold the office of sheriff, deputy sheriff, jailer, superintendent or keeper of any correctional institution for five years thereafter. If the physician certifies that the health of the prisoner requires such liquor, the prisoner shall be allowed the quantity prescribed and no more.