That's not quite the situation.
Firstly, he wasn't charged over classification. The prosecutors used a different law where classification status doesn't matter, sidestepping questions about classification.
Secondly, they charged him with things beyond simply retaining the documents. The alleged lies were themselves criminal, separate from the retention.
But to your main point, no, nothing became illegal retroactively. Rather, Trump's statements gave prosecutors evidence to prove what had always been illegal, allegedly.
It's like, if you publicly brag about robbing a bank leading to your prosecution, it wasn't that the bragging made the robbery illegal retroactively but that it helped prove what had always been illegal.