Spyware is used primarily to access people's electronic devices (usually of journalists, politicians, political activists and human rights advocates) without consent. This is usually unlawful but  national security measures are often invoked to justify the use:
en.m.wikipedia.org/wiki/Spyware