First, differentiate between the court process and justice. Justice is the end result of the court process, so that first has no further part once a verdict is reached. Justice, following a guilty verdict, is made up of the punishment that the convicted person receives, whether it be gaol or community work or whatever.
The generally accepted reasons why this justice system is needed are:
rehabilitation, or in other words turning the 'bad' ways of the convicted around;
punishment