Retribution provides almost no societal benefit. Most of society doesn’t know or care about any individual crime. Rehabilitation of a single member however will benefit all of society, as you can’t predict all possible social interactions of a single person.
Social order, the people wronged want to know that the culprit suffered for it, otherwise said people will start to feel the judicial system is disconnected from justice itself.
I mean, why do you think Lex Talionis is that historically universal?
The caste system and human sacrifice also provide social order. Medieval system of peasants and lords and kings provided social order. Spanish inquisition and torture provide social order.
For my part, I consider inflicting suffering to be fundamentally immoral, because the "moral" justification for retribution relies on the notion of free will, and there is no rational case for free will.