> Just because its their job doesn't mean its okay.
Just because it's the job of the military to kill people doesn't mean it's okay.
It's not, but every single country in the world still has a military, and won't disband it just because "killing is wrong".
Countries have interests. They have a foreign policy aimed at defending these interest.
War is diplomacy by any other means, and countries will use wars as a tool of their foreign policy.
Spying is also diplomacy by other means, and countries will use spies as a tool of their foreign policy, which has the nice benefit of not killing people and not destroying everything, like wars do.
That it is "wrong" in some isolated, ideologically pure version of reality has little impact in practice. Countries continue to spy (since before they were such things as "countries"), and will continue for a long time.