1) Segregation. Taking dangerous individuals and putting them in a separate area away from society.
2) Rehabilitation. Changing the behavior of these individuals to avoid recidivism.
3) Retribution. Just making these people miserable because it people outside prison feel good knowing the people in prison are having a bad time.
The US penal system is designed principally around (1) and (3) and pays lip service to (2).