The following might be a good dichotomy. Suppose you learn the allies have broken the Enigma machine during WWII. Disclosing this is not in the public interest, because the public knows the allies would have a program to break Nazi cryptography and the fact that it succeeded doesn't allow the public to do anything differently, but would allow the Nazis to switch to some other cryptography.
But now suppose that the NSA breaks AES or RSA today. That would be completely different because we use it. The American people would need to stop using the broken cryptography and come up with something better (or use longer keys), and the government keeping it a secret that it's broken is the thing putting the American economy and American lives at risk.
The obvious problem with all of this is that the edges are fuzzy. There are cases in the middle where there is a certain amount of public interest and a certain amount of harm and balancing them is a subjective exercise. But if there was ever a case for a jury to be useful for something, this is it. Making factual determinations like that. Because then you would have to be sure enough in your correctness to be willing to throw yourself on the mercy of 12 ordinary Americans.
The problem is the law doesn't allow that. There is no public interest defense. You're not allowed to make that argument to the jury. So what are you supposed to do, seek asylum in Russia?
A slightly better example might be the development of nuclear weapons. Leaking not just their existence, but detailed plans of how to construct them and refine the uranium on the basis that 'it is immoral for one country to control such powerful weapons'.
That is a plausible moral position that would have catastrophic consequences and would not be revealing illegal activity per se.
Do we prosecute someone like that?