The phrase in its oldest form literally refers to getting away without paying tax. Scot is cognate with the Danish (Scandinavian) word skat which means both tax and treasure - the latter meaning incidently being why it can be used as a term of endearment.
This later was broadened to mean getting away without any punishment. I could find no reference online to its use for show trials.
Sources:
https://www.etymonline.com/word/scot-free
https://www.phrases.org.uk/meanings/scot-free.html
https://www.theguardian.com/notesandqueries/query/0,5753,-27...