The Torah states in numerous places that upstanding societies are predicated on justice:

בְּצֶדֶק תִּשְׁפֹּט עֲמִיתֶךָ – You shall judge your fellow with righteousness (19:15)

Rashi notes that this is not just the approach for formal legal systems and executors of justice; this is how people ought to conduct themselves on an individual level too. The Gemara in Shabbos states that הדן חבירו לכף זכות, דנין אותו לזכות – one who judges their fellow favorably is judged favorably in return.

The Ba’al Shem Tov teaches that when a person gets to Heaven, he is ushered into a courtroom, and is instructed to judge a case. The case is presented, the prosecution speaks, then the defense. The eager new-comer pounds the gavel and declares the defendant guilty. The angels pull him aside, and say, “Reb Yid, this case was actually about you. You are the defendant. Don’t you remember that time you…” He must then answer for all the times he was guilty.

R’ Yisroel Reisman points out that this is why we call this process דין וחשבן – a ruling and accounting. The ruling comes first.

R’ Reisman asks a poignant question – this mechanism will not work on people who already know this. When it is eventually and inescapably their turn to judge, will the people who know better declare everyone and everything innocent, and when informed that they are the defendants, will they feign surprise and be absolved?

The Beis HaLevi explains that the judgment in Heaven is not a new, independent decision.

The judgments we make in our lives will one day be applied to ourselves, and we will be held to the standards we expected of others. All a person truly is, is the decision they have made. Are we real? Do we match up to what we think we perceive to be in the mirror? When you judge another, you do not define them; you define yourself. If you are kind, you will be treated kindly. You project the values and beliefs you have, and one day, which will one day be shined on you.

בְּצֶדֶק תִּשְׁפֹּט עֲמִיתֶךָ is not exclusively about a court system. It is a way of life; a mentality. It is the way to create a community of fair, decent, and good people. Don’t treat people well based on their respective merit, or otherwise. Treat people well purely because you are someone who treats all people well.