From a citizen's point of view, I think of punishment as having several objectives:
1. social engineering - there is a desire to get the general populace to behave in a certain way, so governments often set up laws to threaten the population with punishment if they don't behave in a certain manner. Why want to change the general population's behavor?
Well, in some cases, to provide a reduced risk of harm to the population, reduce costs to businesses, to protect the government itself.
2. revenge - some punishment is designed to provide the victim, their family, or the citizenship some degree of a sense of justice, or at the very least, the offender facing some level of consequences for governmentally established sociatal behavior
3. re-education - an attempt to change the offender's behavior from something that is not deemed socially acceptable to something that is.