Last year I had 2 posts about this (ויקרא משה להושע בין יהושע and ויקרא משה להושע בין יהושע II) where I discussed the difficult Rashi.
I just saw that Torah Temima has a similar answer to the Keren Ora. He says that Moshe davened for Yehoshua because Yehoshua was from Yosef and it says in וישב that ויבא יוסף את דבתם רעה אל אביהם and therefore the sin of lashon hara was something that Moshe thought Yehoshua needed special protection from. He also explains that the derasha in the Gemara is using 20/20 hindsight. Moshe really just davened that Hashem should save Yehoshua, he had no idea about what the Meraglim would do. Later the Gemara looking back added on that he should be saved from the עצת המרגלים.
In truth, this answer is also very difficult. To say the Gemara is looking back with 20/20 hindsight and Moshe didn't say that is very difficult. In addition, according to the Torah Temima why didn't Moshe daven for the representative of Menashe as well as he was also from Yosef.
I saw that others ask, how could Moshe daven for Yehoshua not to sin? הכל בידי שמים חוץ מיראת שמים and therefore you can't daven for someone else not to sin, it his choice.
The bottom line is that for me עדיין צ"ע how to understand the Rashi and the Gemara in Sota.