The goal of penal system should not be punishment, but rather prevention of crime. Punishment is only one aspect of crime prevention.
IMHO, imprisonment has two goals:
1. deterrence, to prevent _another_ person to commit the same crime in the future
2. get really dangerous people away from the general population (this would be rare)
Every crime is a failure of society already. There is no place for revenge or intentionally bad treatment of offenders.