We probably get our best look at penal rehabilitation in Lower Decks’ “A Few Badgeys More”
We learn that Daystrom Institute has a facility dedicated to evil robots, but through therapy, and exploration of art, sports, and other hobbies and psych-evaluations they may earn parole, and from there re-enter society.
Peanut Hamper made it to parole, initially as a ruse, but actually ended up taking it seriously.
Agimus is lagging behind her, but also shows signs of sincere reform.
Honestly, while a lot of it was played for laughs, I really appreciated how it really was Star Trek’s optimism at its peak. People can be reformed, and are not sentenced to life in a cubical if they are capable of earning it.