Spying on foreign countries, especially when they are engaged in war crimes and torture, is not illegal.
Assange is not and has never been a US citizen or permanent resident. What he did is perfectly permissible.
He made a huge mistake in traveling to the UK though.