Tell that to the guys on death row.
That will prevent them from committing further acts, so there's half of it. And that can be a big part of it, depending on the impact that their acts have on the world around them.
The other half, rehabilitation, is a bit trickier - but people don't end up on death row for stealing their buddy's chewing gum in study hall. I think that most or all people on death row are there for murder. Some states also impose that sentence for rape of children, but I don't know if anyone is on death row for that. For some acts, I'd guess that the historical rate of successful rehabilitation is low enough to indicate a near zero probability that the person won't commit the crime again, therefore indicating that life imprisonment or death is the only proven way to prevent that person from repeating the offense. For example, a number of states that impose that penalty for rape of child only do so when it's a repeat offense - and I'm guessing that the statistics on repeat offenders show that they'll just keep doing it until they are stopped.
That said, I have no problem with justice being about retribution. I don't need someone to rape a child twice before I think that they should be put down.