When someone commits a crime and they are convicted, they may be put in prison. What do we hope to achieve through this incarceration?
Incarcerating criminals, particularly violent criminals, might make our society safer. If you remove the dangerous individuals from the general population, so the theory goes, those that remain are the law abiding ones.
(This, by the way, is one of the reasons some people support the death penalty. If the most dangerous criminals are put to death, they will not be able to re-offend, and we are therefore a safer society.)
A second possibility is one of reformation. If someone who has committed a crime is isolated until they experience and show remorse, that person can be rehabilitated. They can then be reintroduced to society.
Yet another is putative. If someone has wronged us individually or as a society, that person needs to be punished. That punishment can take on different forms: removal from society at large; kept in confining or restricting quarters; forced labor; removal from any human contact; etc.
Incarceration can also be seen as a potential deterrent to others. If you break the law, this will happen to you. So you’d better not break the law!
There may be other possible reasons as well. Each one of these has merits and flaws. However, to answer this question we need to answer a different question first: what are we trying to achieve? What is the outcome we want, and what is the best way to get that outcome? Do we want punishment? Do we want rehabilitation?
In other words, what is the purpose of incarceration?