The modern concept of a court is based on the ancient English traditions. To best understand it, imagine how things were in the 12th century. The king was the sovereign. On his throne by Divine Right, he was the source of all law. So went the theory. But the king was as vulnerable to death as was anyone else.
The king is sitting on his throne, gazing out the window, surveilling his kingdom. He notices one of the knaves stealing oranges from his favorite orange tree. No problem. Guards are summoned and instructed to incarcerate the knave for a month in the castle dungeon.
There you have all the elements of basic court procedure: jurisdiction, evidence, accusation, judgment, punishment. The king had the jurisdiction; he had personally seen the violation of his rules (the evidence), then he rendered and executed the judgment. Theoretically, that is all that is needed.
As a practical matter, there is more to the story.
In this case the criminal's brother happens to be the king's chief cook. The cook takes a day off to visit the dungeon. The prisoner complains about the injustice of it all, that he meant no harm, that he didn't do it, and that the king was totally unfair. Mr. Cook, enraged by his brother's story, promises to help. That evening the king dies from a slight overdose of arsenic (that's how the nobility solved problems in those days).
The arsenic factor is what led to our modern court system. The royalty of that period realized that they were vulnerable, so they devised a trial system which would encourage others to not take it out on the king. This resulted in a
The king is sitting on his throne, gazing out the window, surveilling his kingdom. He notices that one of the knaves is stealing oranges from his favorite orange tree. No problem. He summons the guards and instructs them to bring the knave before the court. Papers are drawn up and a formal accusation is published for the world to see. A future date is set, and the knave is given an opportunity to round up defensive evidence and witnesses as well as a king-trained, tested, and licensed defense attorney.
On the appointed day, the king's representative publicly announces the accusations, the defendant publicly states his innocence and the reasons therefor. Great argument is heard for both sides, and the king renders his judgment: 30 dungeon days. Attending the trial are the various court officers: judge, counsellors, marshall, court reporter, court jester, court clerk, and the various courtiers who invariably attach themselves to the seat of power. Among them all is the prisoner's brother, the king's chief cook.
On visiting day at the dungeon, the criminal complains on deaf ears. Brother chief cook says, "Sorry Bro. I was at the trial. I saw the evidence, I saw that you had an opportunity to defend, and I saw that the judgment was according to law. Even if the judgment was in error, the procedure was fair. There is nothing I can do for you."
The king's show was a success! Because of public judicial procedure he is guaranteed a long arsenic-free life, even though there was no difference in the final outcome.
In the first scenario the king acted according to theory. In the second scenario the king acted with prudent life-extending considerations.
Modern court procedure still adheres to the traditions of the past. You can see this in the various rules, statutes, and canons. For example, in Canon 2 of the CODE OF JUDICIAL CONDUCT it is well understood that "A judge shall comply with the law and should act at all times in a manner that promotes public confidence in the integrity and impartiality of the judiciary." There is no specific requirement that he actually have integrity and impartiality beyond that minimum required by law; only that the judge should act in a manner that promotes that image.
Maintaining image while protecting sovereign interests is probably the most important function of a court. The actual effectiveness of a government court in meting out justice has been questioned. Spend a day in any traffic court and you will get the full flavor of how the courts protect sovereign interests as they put on a show of procedural propriety.