Government intelligence is very much distinct from espionage, and is not illegal in the UK, providing that the organisations of individuals are registered, often with the ICO, and are acting within the restrictions of the Regulation of Investigatory Powers Act (RIPA).
In military conflicts, espionage is considered permissible as many nations recognizes the inevitability of opposing sides seeking intelligence each about the dispositions of the other.