Of course, there's nothing that says the host country can't put a captured foreign intelligence officer in prison, or even execute such a person outright, beyond a simple reciprocal convention that such things aren't done. The reason why that generally doesn't happen is the same reason why civilized nations rarely visit atrocities on prisoners of war: a country which unilaterally abrogates such a convention risks having its own personnel treated just as badly.
In the case of espionage, there's the further, and major, consideration that any abrogation of diplomatic immunity risks a general breakdown of diplomatic relations, a state of affairs which between civilized nations generally presages the outbreak of warfare. Aside perhaps from a few madmen who never approached real power, no one on either side of the Cold War ever wanted it to turn hot, and the entire edifice of Cold War-era espionage existed precisely to help prevent that misfortune from ever coming to pass. Imprisoning foreign intelligence officers would, therefore, have been actively detrimental to the purposes of the nations which might have done so.
So, the way we as citizens are subject to the law of our respective governments, is the monopoly of violence. Obviously, a similar mechanism doesn't exist for international law[1], but violating a diplomat is technically casus belli.
Anyway, you're right in that the main sanction is the breakdown of diplomatic relations, but that doesn't mean that the ground rules are vague gentlemen's agreements and handshakes.
1: at least formally -- only a few countries would be able to get away with executing US diplomats without being treated to something resembling a monopoly on violence, yet the Vienna Convention is also respected among countries that could not do that
The article title is a misnomer: she wasn't a spy, she was an intelligence officer under diplomatic cover, handling the people who were doing the actual spying.
Actually, its a differentiation that most journalist and editors fail to make primarily because their publications sell better using the term "spy" instead of "(case) officer" for the intelligence agency employee and "agent" or "asset" for the actual spy that is being run.
Unfortunately, that disservice has existed for decades and is probably difficult if not impossible to break.
The diplomatic immunity is what mattered in this case. If it was someone with American citizenship but no other special status it probably would have gone differently.
Of course, there's nothing that says the host country can't put a captured foreign intelligence officer in prison, or even execute such a person outright, beyond a simple reciprocal convention that such things aren't done. The reason why that generally doesn't happen is the same reason why civilized nations rarely visit atrocities on prisoners of war: a country which unilaterally abrogates such a convention risks having its own personnel treated just as badly.
In the case of espionage, there's the further, and major, consideration that any abrogation of diplomatic immunity risks a general breakdown of diplomatic relations, a state of affairs which between civilized nations generally presages the outbreak of warfare. Aside perhaps from a few madmen who never approached real power, no one on either side of the Cold War ever wanted it to turn hot, and the entire edifice of Cold War-era espionage existed precisely to help prevent that misfortune from ever coming to pass. Imprisoning foreign intelligence officers would, therefore, have been actively detrimental to the purposes of the nations which might have done so.