The purpose of putting to people in jail stems from the 3 Rs: Retribution, Removal, and Rehabilitation. Retribution: punishment for the crime. Removal: removal from society so no further harm can be committed by the individual. Rehabilitation: make the individual a better person so they don't commit more crimes and become better citizens.
Unfortunately, we usually don't accomplish all 3, but 1 of the 3 usually gets done.