yes in some cases
it likely deters some would be mass killers and while we can't prove if it deters people, it certainly is unlikely to encourage anyone
rape and mass murder, things like that, the world needs to be kept in balance to some degree. its now about an eye for an eye, or revenge, its about reactions to actions and setting an example and tone to society
certain things should never be condoned and you can't just keep locking up everyone who does terrible things. like especially terrible, like multiple murders sort of stuff. if they're crazy, okay maybe I get keeping them alive, but a cold blooded mass murder, sociopath or not, there is no reason they should still be on this planet and potentially able to hurt someone else mentally or physically
you call it revenge, I call it giving victims family's and the populace in general peace of mind. a serial killer, for example, is never going to randomly contribute to society again or provide any good. so we feed them, pay money to keep them sitting? why? it becomes a PC pat yourself on the back subject when that's all anyone cares about. setting an example for those who will never care to look or learn