We are in Maseches Makkos, chapter 1, mishnah 7. The mishnah opens by quoting the verse: "Al pi shenayim edim o sheloshah edim yumas ha-meis" - on the word of two witnesses or three witnesses the accused is put to death. In other words, we accept their testimony as valid, and on its strength a death sentence is carried out.
The mishnah's question:
The mishnah asks: "Im miskayemes ha-edus bi-shenayim, lamah pirat ha-kasuv sheloshah?" - if testimony is established and becomes valid on the word of two witnesses, why did the verse need to mention three as well? Two are enough, so what need is there for three?
The mishnah's answer - comparing three to two:
"Ela le-hakish sheloshah li-shenayim" - the verse comes to draw a comparison between three and two: "Mah sheloshah mezimin es ha-shenayim, af shenayim mezimin es ha-sheloshah". Just as three witnesses can refute two witnesses through hazamah - and as the Nimukei Yosef points out, they are the majority - so too two witnesses are fit to refute three. If a set of three witnesses all testified about the same matter, and two witnesses came and said, "You were with us at that time in another place," they have the power to refute the first set, even though it outnumbers them.
"U-minayin afilu me'ah?" - how do we know that even if the first set numbered a hundred witnesses, two witnesses have the power to refute it? "Talmud lomar: edim" - the derivation comes from the extra word. The verse says, "on the word of two witnesses or three witnesses," and it could have said, "two witnesses or three"; the second use of the word "witnesses" is superfluous, and from here we learn that the number of witnesses makes no difference - two witnesses have the power to refute them.
The view of Rabbi Shimon:
Rabbi Shimon takes a different approach and derives an additional point from the verse - he is not disagreeing, but rather understands the verse differently: "Mah shenayim einan neheragin ad she-yihyu sheneihem zomemin, af sheloshah einan neheragin ad she-yihyu sheloshtan zomemin". Just as we do not apply the law of scheming witnesses to two witnesses - putting them to death - until it is proven that both of them are liars, so too with three witnesses who testified together: we do not put any of them to death and do not apply the law of hazamah to any of them, until all three of them are refuted. And here too: "U-minayin afilu me'ah? Talmud lomar: edim" - from the superfluous word "witnesses" we learn that if a set of a hundred testified, each and every one of them must be refuted.
The view of Rabbi Akiva:
Rabbi Akiva offers a third approach: "Lo ba ha-shelishi ela le-hachmir alav ve-la'asos dino ka-yotzei ba-elu" - the mention of three is directed at the third witness, and it comes to be stringent with him and to make his law equal to that of the first two. Had the word "three" not been stated, one might have thought that the testimony of the first two witnesses alone is sufficient, while the third witness bears no responsibility under the law of hazamah and is not given the same punishment, since the testimony was valid even without him. So the Torah came and taught that we are stringent with him and give him a law equal to that of the first two.
A fundamental principle in how the Holy One, blessed is He, runs His world:
From here the mishnah establishes a fundamental principle in the conduct of the Holy One, blessed is He: "Im ken anash ha-kasuv la-nitpal le-overei aveirah ke-overei aveirah - al achas kamah ve-chamah she-yeshalem sachar la-nitpal le-osei mitzvah ke-osei mitzvah". The first two witnesses are the ones who cause the trouble, and the third witness is no more than an accessory to them, and even so the Torah gave him that very same punishment. It is a kal va-chomer: if the verse, meaning the Holy One, blessed is He, punishes the one who joins those who commit a transgression just like the transgressor himself, then He will certainly grant reward to the one who joins those who perform a mitzvah just like the one who performs the mitzvah.
In summary: In this Mishnah we learned that there is no difference between two witnesses and three as far as the testimony itself is concerned, and three approaches were offered to explain why Scripture mentions three: the comparison of two to three regarding hazamah (being proven false through the testimony of others) - and even a hundred, derived from the superfluous word "edim"; the view of Rabbi Shimon, that the law of hazamah does not take effect until all of them are proven false; and the view of Rabbi Akiva, that Scripture comes to be stringent with the third witness and to make his law equal to that of his fellows. From here emerges the great principle: joining in itself creates partnership and responsibility - one who attaches himself to sinners is punished like the sinners, and all the more so one who attaches himself to those performing a mitzvah receives reward like the one who performs the mitzvah.