In olden times, although the source is uncertain, a scot was the amount that one owed for entertainment, usually the amount of one’s share in that entertainment, as for the drinks in a tavern.
Scot-free thus described one whose debt was assumed by others or whose drink was “on the house.”
From that beginning, the meaning of scot-free came to be freedom from other kinds of payment, as taxes or tolls, and from that it became extended to freedom from punishment.