It's not just supposed to be a punishment and it's obviously not a deterrent. Rehabilitation and allowing for proper reintegration into society needs to happen or you end up with a former felon being stuck in a cycle of crime that they are forced into.
While I agree with your assessment of private prisons, I think we've begun to use the legal sure and imprisonment for things it wasn't intended for, such as minor vice crimes, based on flawed broken window thinking and making police terrified of the communities that they serve.