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 for the offence committed;
protection of the community from a repeat offence by the convicted person.
From a different outlook, sort of sociologically, a criminal justice system is needed simply because too many people commit offences against others.
Having such a system also acts, in theory, as a deterrent to people who may be considering a crime - the fact that they will be punished if caught and convicted is supposed to put them off the idea. You can judge that for yourself - look up statistics on crimes committed as opposed to crimes solved, and you will readily see that far more crimes are committed than are solved, which is a great worry to the community, and leads to many serious problems, including vigilantism and a somewhat frantic drive to get people convicted. This last, in turn leads to around 1 in 5.5 prisoners in the US being ' wrongfully convicted'.