כֹּהֵן קוֹדֵם לְלֵוִי, לֵוִי לְיִשְׂרָאֵל, יִשְׂרָאֵל לְמַמְזֵר, וּמַמְזֵר לְנָתִין, וְנָתִין לְגֵר, וְגֵר לְעֶבֶד מְשֻׁחְרָר. אֵימָתַי, בִּזְמַן שֶׁכֻּלָּן שָׁוִין. אֲבָל אִם הָיָה מַמְזֵר תַּלְמִיד חָכָם וְכֹהֵן גָּדוֹל עַם הָאָרֶץ, מַמְזֵר תַּלְמִיד חָכָם קוֹדֵם לְכֹהֵן גָּדוֹל עַם הָאָרֶץ:
Ein Priester geht einem Leviten vor, ein Levite einem Jisrael, ein Jisrael einem Mamser, ein Mamser einem Nathin, ein Nathin einem Proselyten, ein Proselyt einem freigelassenen Sklaven. Wann gilt dies? Wenn alle (genannten Personen) gleichwertig sind; ist aber der Mamser ein Gesetzkundiger, der Hohepriester aber ein Unwissender; so hat der gesetzkundige Mamser der Vorzug vor dem unwissenden Hohenpriester.
Bartenura
כהן קורא ראשון – When they are equal in wisdom, but if the Israelite is greater in wisdom, he precedes the Kohen and the Levite (see Mishnah Horayot, Chapter 3, Mishnah 8) for a Sage who is illegitimate comes before a High Priest who is an ignoramus. The law is the law of the Gemara, but today it is the practice that the Kohen, even if he is an ignoramus, comes before a great Sage who is an Israelite.
Binyan Yehoshua
That a mamzer does not enter Jerusalem. Even though it says at the end of Tractate Horayot (Horayot 3:8) that a learned mamzer precedes an ignoramus high priest. As it says (Proverbs 3:15) "She [wisdom] is more precious than rubies", from a high priest who enters within and beyond. Nonetheless, the holiness of Jerusalem is unable to bear him, since its holiness is very great -- one who does not have proper lineage, such as a mamzer, would not be able to have settlement in Jerusalem. And so it is written "And a mamzer shall dwell in Ashdod, etc." (Zechariah 9:6). Commentated.