For each day’s labor the prisoner shall be credited $3 on any judgment for fine and costs and, when imprisoned in default of payment of a fine or fine and costs, the prisoner shall be discharged when the prisoner has performed sufficient labor to pay the same. The officer in charge of such prisoners shall protect them from insult and annoyance while at labor or going to and returning therefrom. Every person who shall insult, annoy, or communicate with such prisoners, after being by such officers commanded to desist, shall be guilty of a misdemeanor and punished by imprisonment for not more than five days or by fine of not more than $10.