In theory it is the second one but in practice it is the first all the way.
Sadly because of the misuse of the prison system the first has become the only real reason for it. The clearest example of this is the fact we lock up non-violent offenders, many who have committed crimes that have no violated party at all, such as drug users. These offenders do not need to be isolated from society to be rehabilitated, most need medical help and many of these non-violent criminals come from the fact our societies are cold and uncaring towards those who suffer the most. Social programs to help the most needy go far further to lowering the crime rate then the prison system can ever boast, by eliminating the need for petty crimes to begin with.
Coupled with the fact we allow violent offences to go ramped through the prison system, ironically carried out by the violent inhabitants whom prison was designed for, and wield the mess that formed around as a 'big stick' to keep people in line says all that needs to be said about the prison industry. Most of the people who have come out of the prison system as it stands today are WORSE then when they went in. So many will willingly admit it too as all prison taught them was to 'harden up!' It does squat to address the issues that made them turn to crime in the first place, so very few people come out changed for the better. This means most of the released parties will still be impartial to crime, finding themselves in the same positions that started their criminal actions to begin with, but are now less caring about those around them.
It is nothing more then a big stick and a big business!
Never forget that, the prison industry is private owned and makes millions and billions a year. The people who profit from this system are invested to see their business grow. They are the ones that back, heavily, propositions that will criminalise more things, have longer sentences to even petty crimes and in many states have made it so a petty criminal will never be released. Criminals are the new slaves, forced to work for cents through a range of legal and semi legal punishments for non-compliance.
This is how they make massive fortunes!
There is a reason why the US is the worlds foremost country when it comes to people locked behind bars... it makes rich people even richer.