On the egoist premise this is fine and dandy, but it is an intolerable contradiction for altruists. An altruist is one who holds that selfishness is wicked, and that unselfishness is the essence of morality. Because punishment necessarily falls on the unselfish, and spares the selfish, this means for an altruist that it falls on the moral, and spares the immoral. Altruists must regard punishment as inherently immoral. And they do.
Leftists are altruists.
That is why they try to pretend that penal institutions do not inflict punishment. The punishment motive is the flip side of the profit motive. Altruists oppose both. Therefore, if punishment cannot be entirely abolished, it should be watered down to impotence. Now we can understand the actual meaning of the mantra that punishment does not deter.