I found this rule in an English book on spy novels (a history of the genre, not a writing guide) back in the early '80s - the title and the author have escaped me.
However, the rule holds up in about every type of narrative (film, TV, literature...), even today.
The rule is this:
Betrayal is loved; the traitor is hated.
In other words, treachery and betrayal are a narrative element much beloved by audiences all over the world. Certainly in spy thrillers, you cannot have enough betrayal, so to speak.
However, the character performing the betrayal is not so lucky. For some basic psychological reason, the traitor is always punished, usually by death.
It doesn't matter whether the traitor is on the side of the villains or on the side of the angels - retribution always seems to follow. The villainous traitor always gets his/her comeuppance somehow; the goody-two-shoes traitor is invariably found out by the bad guys and usually 'rewarded' with a fate worse than death.
You may doubt the universality of this rule, but try it yourself - you will be amazed to discover in how many films and novels this narrative gambit appears.
The one exception to the rule is in Bruce Willis' vanity action comedy Hudson Hawk. Bruce's partner Danny Aiello betrays him in the course of the film, and dies soon after. However, at the very end of the film, Aiello pops up unharmed. But it's a sort of post-modern gag: the explanation Aiello gives for his survival is so incredibly far-fetched, that both the characters in the film and the audience are supposed to realize this is a narrative cheat in order to ensure a completely happy ending.
The fact that only the notorious Hudson Hawk (a misguided movie if ever there was one) dared to challenge this convention should act as a warning to screenwriters who would like to attempt the same feat. Which is not to say it shouldn't or couldn't be done - only that you'll have to fight an enormously powerful 'cliché' (for want of a better word) which seems to have a deep-rooted psychological foundation.
But pulling it off succesfully would enrich the narrative vocabulary for storytellers everywhere, as breaking this narrative shape could be re-used time and again (unlike, say, the rule breaking in Psycho which is basically one-trick ponies. Kill your protagonist off halfway through the film, and the audience reaction will be: 'Hey, that's just a Psycho rip-off!')