The problem is rehabilitation only works on some people, and punishment works on virtually no one.
Prisons are a dumping ground for people with personality disorders. You can't fix a personality disorder with rehabilitation, or with punishment. (Arguably you can't fix a personality disorder at all.)
Some people are relatively rational. They commit crimes for a variety of reasons, a good proportion of which are a direct outcome of poverty and/or economic abuse and/or racism.
The best way to rehabilitate them is to rehabilitate society so it doesn't push them into a corner, or create subcultures where crime is a reasonable survival option.
The people with psychological issues are much harder to deal with. Keeping them locked and away and occupied is more humane than trying to "punish" them, because the punishment is pointless and will have exactly zero effect.
Running prisons as a for-profit industry instead of a social service is barbarism, and ultimately just puts more criminals on the streets.