I agree with Phil. If the government wasnt planning to backpunish people for breaking laws then why on earth is the NSA building massive datacenters and collecting unbelievable amounts of data on everyone to store forever? You really think at some point they wont have AI going through that to try and bleed people dry in order to push their agenda?
Laws are different everywhere; as far as I know, in most places you can (and should) be punished for something that was illegal when you did it, even if this fact is only discovered later.
'Back punishing' in the sense of punishing someone for something that at the time was permitted, is at least morally, really fucked up. Because how could you have 'been a law-abiding citizen' without a time machine, then?