The first time someone encounters the criminal justice system, barring an extreme case such as rape or murder, the purpose of prison should be to determine 1) if the person can be rehabilitated and 2) how best to rehabilitate the person if rehabilitation is possible. Someone who shoplifted because they've been poor all their life and doesn't have any options could be rehabilitated provided they had the proper knowledge, skills and drive to want to make more out of their life.
Most people should have the option for a second chance, but they have to want to take it. Once they decline that second chance, or if they find their way to prison for a third, fourth or fifth time, at that point prison becomes a way of preventing the criminal from doing harm to others by keeping them away from society.
It depends strongly on the crime that was committed and it depends on the person.
Criminals like Ted Bundy and John Wayne Gacy could not be rehabilitated. Ted Bundy couldn't resist his urges and his hobbies and passion was rape and murder itself. He was proud of it. John Wayne Gacy's passions were the same. He was proud of it. The only appropriate answer was Capital Punishment. It was only fair, after all you should look up the number of victims they murdered.
Now if we're talking about petty crimes like theft, illegal drug possession, and speeding. I can see people like that being rehabilitated and being brought back into society. I know a guy in my town that owns his own business and claims he went to prison for attempted murder. His story begins that he worked in a factory. His boss upset him. He lost it. He grabbed and threw his boss into a metal shredding machine. Everyone intervened and pulled him out. His boss was mildly injured. He pressed charges. He got 15 years in prison. He claims he doesn't regret it. He got out, got married, started his own business, and had kids. He's back in prison now. I don't know why.