The gem in Archin (32) writes that the name of Yehoshua is written chaseir in Nechemya 8 because he failed to eradicate the yetzer hara for avodah zarah and his mission was incomplete. Moshe was unable to do so because he lacked the zechus of Eretz Yisrael, yet Yehoshua should have taken care of it - instead the problem lingered until generations later. The Radomsker (Tiferes Shlomo) asks why the gemara is so critical of Yehoshua and not any of the other shoftim, nevi'im, and tzadikim who might have also been mevateil the yetzer hara in their day. Aren't these other historical figures equally guilty for their complacency? The Radomsker explains that the yetzer hara serves a function in creating the opportunity for bechira. Had we not had an inclination to do evil, we would lack free choice. Even the nevi'im and tzadikim were not enpowered to void the principle of bechira by eradicating the yetzer hara. However, in order to insure kibush ha'aretz Moshe was mispallel "K-h moshiacha m'atzas meraglim", that Yehoshua not be tempted by the advice of the mergalim. Yehoshua's free will was already negated in part by Moshe's tefilos! Therefore, specifically Yehoshua, who transcended pure bechira, had that power to be mevateil the yetzer, but he did not seize the opportunity.
I want to add one point to the Radomsker's chiddush. It seems safe to assume (at least as far as what Moshe's impression might have been) that Moshe's prize student would not fall prey to the temptation of an actual sin in deed. However, there was still the danger that in the back of Yehoshua's mind there would be some measure of doubt, even if never voiced, that one day might resurface to cloud his judgement. Moshe therefore gave his talmid a bracha that "K-h", the letters Yud and Key that refer to the higher sefiros of thought, chochma and bina, "moshiacha m'atzas meraglim", should give you the strength to overcome even the poisonous thoughts of the spies. Chazal teach that only for the cheit of avodah zarah Hashem is metzaref machshava l'ma'aseh, that one is judged even for the thought of wrong even if not acted upon. Perhaps it was this added bracha of protection on the deepest level of his thoughts which gave Yehoshua and no one else the potential to uproot the yetzer of avodah zarah from even from the thoughts and consciousness of Klal Yisrael.