A lot of talk about punishment=revenge/retribution. There may be an element of that for some, but on the whole I disagree.
The main purpose of any punishment is as a deterrent, both to those being punished to dissuade them from reoffending, and as an example to dissuade others. If the punishment is incarceration, then it also serves the purpose of physically preventing reoffending for the duration of the sentence (with the exception of crimes committed in prison).