The question is a false dichotomy. A useful justice system will do both as part of its role in protecting society. Punishment act as deterrence while rehabilitation provides hope. It is a basic carrot and stick approach to influencing a person. Threaten to lock them in a box if they are bad while offering a better lifestyle if they are good.
Many of the flaws in the American justice system are because the system fails to provide both requirements. Drug crimes have severe rehabilitation problems because prison is essentially a training ground and networking club for gangs. White collar crime has both limited prosecution and weak punishment, so there is little deterrence to illegal behavior.