Would you pick killing a spy over stopping your yields from leaking out?
It is always unpleasant if someone's spy is conducting his operations in your city and you want to kill him. But a guaranteed 100% kill is too much punishment.
If the spy is discovered, then it takes him an average of 5 turns to re-arrive in the city - some cities are further away, others are closer. And the target city for the spy can be chosen by someone else if the priorities of the enemy empire have changed.
Or the spy can be sent as a diplomat. By the way, I don’t know if the number of votes available for purchase depends on the level of the diplomat. It would be nice if a top-level diplomat could buy more votes or get a significant discount - let's say 5% for each level above beginner. Also, a diplomat could increase the value of a caravan to this city - the bonus is not too significant, since only one caravan can be sent to any city, but for long-term friendly relations between empires, it's quite good. Peace-loving empires will receive passive bonuses, which in the end can be more valuable than the aggressive capture of enemy cities when trying to dominate or try to steal.
In addition, the mass extermination of spies will destroy the very mechanics of espionage. The most profitable action would be to send your spies to city-states or leave them in your cities for some bonuses, instead of risking spending 5 turns on a trip, 20-30 turns on a mission, making some profit (which will not greatly affect the income of our empire on the entire game distance), lose a spy and wait for a new one for another 20 utrns with 0 experience level. Instead, a spy can sit in our city and at least stabilize happiness, which will ensure non-stop growth in population and production.