Indeed this is strange that the Mishna talk about the story of YBG.
Melechet Shelomo
ע"כ: ואיתא בת"כ סוף פ' ב' דפ' אמור:
ומינהו המלך בגמ' דייקי' מדקתני מינהו ולא קתני נתמנה דקשר של רשעים הוא שהכניסה מרתא בת בייתוס תרקבא דדינרי זהב לינאי מלכא עד דבעא לאוקומי ליהושע בן גמלא בכהני רברבא ומ"מ מצינו בו שתיקן תקנות גדולות בישראל כדאמרי' בבבא בתרא ברם זכור אותו האיש לטוב ויהושע בן גמלא שמו שאלמלא הוא נשתכחה תורה מישראל: וראיתי שהגיה ה"ר יהוסף ז"ל גמלה בה"א מרתה בה"א:
Despite that his wife, who came from a rich family, gave the king a great amount of money for his nomination for kehuna gedola, however he made a big program for Tora to spread education for children, that every community must pay a teacher (in the second chapter of Baba Batra). It's his merit if Tora was not be forgotten in Jewish people.
Ritba says (Yevamot 61a)
. in a first interpretation that this Yehoshua Ben Gamla was an homonym, not the known as righteous.
. In a second pshat he says that he became righteous afterwards.
But we can argue that even if not a first choice for Kehuna gedola, YBG was already known as Tsadik and Talmid Chacham. Perhaps he didn't know that his wife gave money to the king. The pshat of Gemara is that Gemara makes a Dyuk. The dyuk is that in this story which is a Maase Rav because of the greatness of YBG, there is an allusion to what is happened behind the scenes.
This is clear from the way Gemara addresses the maase
מנהו אין נתמנה לא אמר רב יוסף קטיר קחזינא הכא
He (the king) nominated him, he was not regularly nominated (by Kohanim and king). Rav Yosef said I see in this formulation of the Mishna an allusion of protectionism (link between reshayim). But this is the dyuk, not the main teaching of the maase.
So the maase has two levels of teaching.
Pshat pashtut. The standard pshat of Maase Rav
Deduction from the style of the Mishna. The behavior of his wife and the King.
See also Mishna Yoma 3.9
וְקַלְפִּי הָיְתָה שָׁם וּבָהּ שְׁנֵי גוֹרָלוֹת. שֶׁל אֶשְׁכְּרוֹעַ הָיוּ, וְעֲשָׂאָן בֶּן גַּמְלָא שֶׁל זָהָב, וְהָיוּ מַזְכִּירִין אוֹתוֹ לְשֶׁבַח.
עַל הָרִאשׁוֹנִים נֶאֱמַר (מִשְׁלֵי י, ז): “זֵכֶר צַדִּיק לִבְרָכָה",
Bartenura
בן גמלא - יהושע בן גמלא כשנתמנה להיות כהן גדול עשאן של זהב:&rlm:
Yehoshua Ben Gamla did Kalpi from gold. And they say about him (not he alone) the remembering of Tsadik is blessing.