There are sad truths that need to be accepted.
There is no absolute justice. Justice, like virtue, depends upon where you stand. The justice and virtue of the Roman was not that of the Hun.
Law is a code which enables communities to live together without undue violence and exploitation. It is variable according to the society that generates it. The law of Athens was not the law of Sparta.
Many so-called criminals break the law because they are damaged, hurting or economically disadvantaged. The crimes must be punished while the law stands, but society must look to its' values and practices to prevent these crimes from happening.
Some commit crimes for pure greed. The only answer to this is punishment. Punishment which must begin with reparation to the victims. The person who commits crime through greed must lose all they have gained by their actions.
Others, few but still too many, commit crimes because they can, or because they must. These are the twisted, the broken, the emotionally and mentally malformed from birth. The mind is not the body. A body malformed from birth can be repaired, or supported, or improved, by medicine and technology. The mind, malformed from birth, cannot. Mental illness as an acquired behaviour can be ameliorated or managed when it cannot be cured. Congenital mental and emotional problems of a harmless nature can also be managed. But the psychopath, the sociopath, the paedophile, are what they are. The cannot change and seldom really want to. To set them free is to risk others. To imprison them for life is inhumane. Euthanasia - never to be undertaken lightly - is the only humane option for some.
The needs of the many outweigh the needs of the one.