Section 50. No officer in attendance on any court, sheriff, deputy sheriff, jailer, constable, city marshal or other police officer who receives a salary or an allowance by the day or hour from the commonwealth or from a county, city or town shall, except as otherwise hereinafter provided, be paid any fee or extra compensation for official services performed by him in any criminal case; or for aid rendered to another officer; or for testifying as a witness in a criminal case during the time for which he receives such salary or allowance; or for services or as a witness at an autopsy or inquest; or in proceedings for commitment of mentally ill persons; but his expenses, necessarily and actually, incurred, and actually disbursed by him in a criminal case shall be paid by the commonwealth. Whoever receives extra compensation or a witness fee in violation of this section shall be punished by a fine of not more than one hundred dollars.