Any penalty resulting from a violation of this subdivision shall be paid by the owner, if known and resident in the town, otherwise by the occupant; and any tenant who may be compelled to pay the penalty may deduct and retain the amount thereof, and of the costs, from the tenant’s rent, or may recover the same of the lessor in an action for money paid to the tenant’s use.