I have very serious doubts about the efficacy of punishment as a means of moral improvement. Measures traditionally associated with punishment may still be justified, just not on the basis that they will make anyone a more ethical person.
With children, the purpose of disciplinary action is to rather to mold their outward behavior and habits in what we judge to be more responsible and safe directions. With apparently incorrigible and dangerous criminals, the social purpose is to protect others.
Needless to say, the real purposes should be borne in mind in the application of punishments. Cruel and unusual — or otherwise excessive or unnecessary — punishments have been given a veneer of rationalization from claims that they somehow morally benefit those on whom they are inflicted.
In cases where there are obvious victims, positive redress to the victims is appropriate where feasible, but the simple desire to see the perpetrator punished is just a desire for a kind of revenge, having little to do with actual justice. The legitimate concern is to prevent the perpetrator from harming others.
So-called victimless crimes are often associated with various kinds of social issues. In those cases, we should deal with the underlying social issues, rather than blaming individuals. Many crimes with real victims also have more to do with social issues than with real evil in the hearts of the perpetrators. (See also Blame and Blamelessness; Stubborn Refusal; Self, Subject.)