We generally refer to that as incapacitation: you're actually removing someone from society who is dangerous, and therefore they're posing less of a risk. I don't think it has much, actually, to do with deterrence.
Deterrence would kick in if the person, because of experiencing the penalty, decided not to offend in the future because of having learned accountability and having chosen not to reoffend in the future. There is some element of that, but it is certainly augmented if the person is given the benefit of rehabilitative programming and is encouraged to address some of the underlying conditions, such as drug addiction and others, that may be informing the criminal conduct.