I like how JPII explained it: in a place where there the public can be well-protected from the criminal and the danger his ongoing life creates, then there is no need to kill him and life in prison should suffice. (This was his opinion, not an ex cathedra statement). However, in a situation where that’s not possible, the state can do what it has to do and kill the criminal.
For example, when Saddam Hussein was tried and hung. There were a lot of people still in Iraq who would have busted him out of jail, if he were incarcerated for life, and his continuing to live would cast a deathly shadow over a country tying to re-boot. Hanging him wasn’t wrong.
JPII started this slippery slope. You should read the link at post 21.