Except they were avoiding tax in the rest of the EU, so the EU can fine Apple for skirting taxes on products that were actually sold in those other areas.
tl;dr - EU makes rules that companies need to follow no matter which EU country they operate in.
I don't agree that "retroactively made illegal" is the same thing as "illegal", nor should it be called "skirting taxes" when everyone who was involved was okay with it until today where the EU unilaterally decides to alter the deal and punish apple.