The main purpose of prison is not rehabilitation, or deterrence, but to put dangerous individuals away so they cannot terrorize others. This is why we put rapists in cells (or, at least we try to) - every year in a jail cell is a year they aren't raping women.
the main purpose is punishment, see: nonviolent drug offenders in prison
one might argue a higher level purpose is to keep "the right people" in prison, where they lose their freedom, sometimes including the freedom to run against, campaign against, and even vote out the politicians keeping them there