In the Metaphysics of Morals, Kant describes the connection of law and punishment in the following simple relation: if you violate a law, it is a violation of the security of some right or rights for everyone else, and so your own same right should be made insecure. After this, the Doctrine of Right proceeds to discuss a legal system that seems familiar, involving a central authority that meets out punishment.
Given the manner in which the rights of the criminal are made insecure, it does not seem necessary that any punishment over and above this naturally follows. Why could the judgment not merely end at the removal of the rights of the individual until such a time when they can be returned? Of course, if you have committed a murder, and now are made insecure concerning your own life, the result could be worse (in brutality) than a punishment met out by the state: vengeance can be very bloody indeed. However, there is also the possibility of forgiveness of the deeds which is impossible by means of punishment, and which also seems more needful and just than any punishment.
This accords better with the state, since the state ought to be concerned with the maximum freedom of all of its members, and so a violation of rights and subsequent exclusion from the state in certain ways (with the possibility of readmission), allows the state to strive to include a maximum of individuals with differences, but can exclude those who must make the state insecure.
The human being, taken practically (morally), is the agent of his actions. There is no mechanism we can place underneath the actions of an agent without also destroying the form of practical thought that we think him under. Any absolving of crimes that are met out through some kind of mechanism which measures out a particular amount to be repaid will never be commensurable with crimes committed by an agent: such correction must be reserved for mere equipment. This is why it makes sense to untangle the theoretical and practical in this case, and require that forgiveness be the only means of absolution for crimes. Forgiveness does not accept the crimes committed, but it accepts the person in spite of them.
The degree to which we take as quite natural and fitting the punishment of individuals as a means of making amends for crimes, or the correction of these individuals as if they are broken equipment, is also a degree to which we take people as mere objects. If justice is to concern persons in their full humanity, then the treatment of humans as mechanical also stands for the impossibility of real justice.