“Based on the words of two or three witnesses shall the matter be established” (Devarim 19:15). While absent cause, we have little reason to doubt the integrity of any particular person, the Torah was afraid that the testimony of one witness—as well meaning as it may be—is likely to contain errors. Only the cross examination of two witnesses done separately gives the court the confidence that events unfolded as described. The witnesses must corroborate each other on every major point: who did what when. While they are not expected to know ancillary points, i.e., what colour shirt someone was wearing, if the witnesses do contradict each other even on such an ancillary point, their testimony is rejected. The witnesses must speak with one voice.
This is the precise opposite of how the court itself is meant to operate, where dissension is the order of the day. At all three levels of the court system we insist on an odd number of judges–three, twenty-three and seventy-one–so that a verdict can be reached on a split vote. Most famously and astoundingly, when it comes to a capital case, a vote of 23-0 to convict means the defendant goes free. Such a vote indicates that no serious attempt to see both sides took place (is it realistic to have 23 Jews and only one opinion?) and absent discussion and dissent, there can be no justice.
Witnesses report and judges analyze. The reporting must be consistent and the analysis anything but. It is for this reason that Jewish law states ein eid na’aseh dayan, that one who is a witness cannot become a judge on any given case (Sanhedrin 34b). The roles do not mesh and in fact, are contradictory. If we are afraid that witnesses whose job is to report the facts may lie or unconsciously be biased, we must be doubly afraid of such by judges, where much more judgment is called for.
“Rav Yehuda said: One who is a friend or an enemy [is invalid]. They said to him, the Jewish people are not suspected of such” (Sanhedrin 27b). We are naturally biased towards our friends and against our enemies and hence, Rabbi Yehuda argued that one may not give testimony or sit as a judge in a case involving a friend or an enemy. The Sages disagree, arguing that we ought not to suspect that one will knowingly misrepresent the truth to help a friend (or hurt an enemy).
Rashi (s.v. lo) immediately points out that the Sages only disagree with Rav Yehuda regarding witnesses, but they do agree that judges are disqualified from sitting on cases in which one of the litigants is a friend or enemy. With the role of the judge not to report but to analyze, we are fearful that the judge might display bias—even unwittingly. While in the case of testimony there is also a possibility of hidden biases, the risk factor is much less. Our Sages understood it is impossible to eliminate every possible bias. With a desire to allow all to give testimony – as opposed to judgment, where only the very learned should sit - our Sages drew the line between testimony and judgment.
Of course, it is also possible—though very sad—that a judge would knowingly display bias, covering up his lie as an “(mis)interpretation” of the law.
“And he was not his enemy, neither sought his harm” (Bamidbar 35:23). If, however, he was his enemy or sought his harm, his testimony could not be accepted. From the double language, Rabbi Yehuda derives that friends (or enemies) of the litigants may not serve as witnesses or judges. The Sages, however, allow witnesses who “might seek harm”, thus creating a redundancy in the verse. They explain that redundancy is the Torah’s way of instructing that “from here, [we learn] that two Torah scholars who hate each other may not litigate a case together” (Sanhedrin 29a). Instead of searching for the truth, they are liable to search only for those arguments that refute the views of their hated colleague on the court. And about those who use Torah for the purpose of showing up one another, “It would have been better had they not been created” (Tosafot Taanit 7a, s.v. v’kol).
“Rabbi Elazar said in the name of Rabbi Chaninah: Torah scholars increase peace in the world” (Brachot 64a). A Torah scholar who hates another Torah scholar should be an oxymoron. Unfortunately, it is not. As is the case with many people of great accomplishment (and some of lesser accomplishment), Torah scholars all too often harbour jealousy towards others who may “compete” with them.
When all is said and done, our court system must be a vehicle for reconciliation, for resolving disputes and bringing people together. And such must start at the top, with our Torah scholars leading the way.
 Rashi is seemingly fearful only of active bias and is concerned that a judge who dislikes a litigant is not going to search and turn over every stone to try to acquit them. According to this logic – rejected by the Rambam and the Shulchan Aruch – only an enemy would be invalidated, but not a friend.
 As some have wryly noted, the Gemara brings scriptural support for this assertion. Apparently, the increased peace is not obvious, and we can be certain of such only because of the scriptural verse supporting such a claim.
 That this is the last teaching of masechet Brachot, the first tractate of the Talmud, is no coincidence. See here for a discussion on why it is also the concluding teaching of masechtot Yevamot, Nazir and K'ritut.
 As to why one who harbours hatred is not invalidated for any and all testimony, disqualification requires one to do a concrete, forbidden action. Feelings, even speech, do not qualify, despite the serious wrongdoing involved. It is why speaking lashon hara does not get one invalidated from testimony. (Not to mention that if we had such standards, our court system would have to close down.) At the same time, a court always reserves the right to throw out testimony it believes is untrustworthy, even if they have no hard evidence (Shavuot 30a).