The Times, by publishing classified information, were themselves potentially violating the Espionage Act (according to the government's assertion) - so the principle applies in more ways than by proxy. Which is why it was vital that the courts ruling affirmed the importance of a free press, despite laws that might be used to gag it.
Classified information is public information (belongs to the government and have a deadline to be disclosed), so makes sense to apply the same principle of New York Times v United States (1971).
But hacking private phones sounds like a new question to me.