There's several interlocking questions you're raising.
First, there are three major theories of why we punish crime as a society. You've identified two:
- Reform - that the punishment is about rehabilitating the criminal (a view largely associated with Mill)
- Deterrence - that by having punishments we decrease crime
- Retribution - that crime requires punishment on some level. This sometimes called "just deserts"
The first two views were quite popular throughout the early and mid twentieth century. They largely led to the elimination of physical punishments in the Western world.
The empirical data, however, has not boded well for them. By and large, punishments do not have the deterrent effect people hoped for and incarceration has not effectively transformed criminals into model citizens. Instead, it seems like it has amped up criminality on the whole.
The philosophical champions (or at least supposed ones) of the punishment account are Kant and Hegel. For Kant, the passage most often cited is a claim that before we could disband society, we must for the sake of justice make sure we punish every criminal or else we would be unjust. For Hegel, this is built into the metaphysics of Right as explained in the Philosophy of Right -- that crime is a violation of right and can only be reversed by coercing things back into the right way with punishment.
Less philosophically, there's always an open question about punishing as retribution for crime and whether it's revenge. The philosophical defenders of retribution have usually separated their views from this (whether this succeeds or not is not something I will try to argue here), and they've usually separated it on the following grounds: (a) "revenge" is done by the aggrieved party whereas "punishment" is done by the people as a whole and (b) "revenge" is often disproportionate whereas "punishment" should be proportionate to wrong. (Though it may not be proportioned based on physical damage but rather value).
This doesn't have very much to do with religion, but there's no reason why a divine command theory could not generate either a system of justice built on retribution or one built on deterrence and reform. (or even one that accounts for all three).
Stated another way, that God commands punish wrongdoing wouldn't explain why God commands or at least would not explain it by itself.
- Hegel, G.W.F. Elements of the Philosophy of Right
- Murphy, Jeffrie. "Does Kant Have a Theory of Punishment?" Columbia Law Review
Vol. 87, No. 3 (Apr., 1987), pp. 509-532
- SEP entry on Punishment
- Scheid, Don. "Kant's Retributivism" Ethics Vol. 93, No. 2 (Jan., 1983), pp. 262-282
- myself (I have a published article on this).