According to the Oxford English Dictionary, the phrase dates back to Old English. "Scot" in this case comes from the verb "sceotan" which meant "to shoot" but it also meant "to pay" or "to contribute". Old Norse has a similar word, "skot", which also means "to contribute".
So "scot" in Old English actually referred to a "royal tax". "Scot-free" referred to a situation where you didn't have to pay the royal tax.
Interestingly, the etymology of the noun "shot" as in something you might do with a gun, comes from the same Old English root as does the "scot" in "scot-free". They both ultimately stem from an older Germanic word. But "Scot" as in "Scotland" has an entirely different etymology, and is derived from a Latin word, "Scotti", from Roman Britain times, which (for unknown reasons) was the Romans' name for the Irish.