Parashat Shelah is famous for the story of Het Ha'meragelim – the sin of the spies. Moshe sent twelve men – one representative from each tribe – to survey the Land of Israel and report back to the people, and when the spies returned, they persuaded Beneh Yisrael that they could not conquer the land, for which thy were severely punished.
The Torah makes a point of mentioning that before Moshe sent the spies, he renamed one of them – his faithful disciple, Hoshea – changing his name from "Hoshea" to "Yehoshua" (13:16). Rashi explains that Moshe gave Yehoshua this new name as a prayer that he would be protected from the sinister plot of the other spies. The name "Yehoshua" can be read as a combination of the words "Y-ah Yoshi'acha" – "G-d shall save you." This was Moshe's prayer that Yehoshua would not be influenced by his peers who would decide to speak negatively about the Land of Israel and sow despair among the nation.
We must ask, why did Moshe pray on behalf of only Yehoshua? If he anticipated the likelihood that the spies would betray their mission, and seek to dissuade the people from entering into the land, then why didn't he pray that they should all be protected from this grave mistake?
The Lubavitcher Rebbe (Rav Menachem Mendel Schneerson, 1902-1994) answered this question by noting Targum Yonatan Ben Uziel's translation of this verse. Targum Yonatan writes that Moshe changed Yehoshua's name because he noticed "Invatanuteh" – Yehoshua's unique humility. Somehow, Yehoshua's especially humble character necessitated this prayer, that he should be protected from sin as he embarked on this mission.
The Rebbe explained that normally, one cannot pray for another's Yir'at Shamayim (fear of Heaven), that the person should do the right thing and avoid wrongdoing. The Sages famously taught us, "Ha'kol Bi'ydeh Shamayim Hutz Mi'yir'at Shamayim" – "Everything is in the hand of Heaven, except the fear of Heaven." We can and should ask Hashem for that which lies beyond our control. Religious observance, however, is our responsibility. We cannot ask Hashem to make somebody religiously committed – because he needs to motivate himself to be committed.
But if so, then Moshe's prayer for his disciple is very difficult to understand. How could Moshe pray that Yehoshua do the right thing, if one cannot pray for somebody else to avoid sin?
The Rebbe answered that we can pray for somebody's spiritual success if that person is already investing effort to achieve spiritual success. For example, we cannot pray to Hashem to help somebody wake up in time for Shaharit if he goes to sleep late and doesn't bother to set an alarm clock. If, however, a person who has this weakness – often failing to get up on time – makes an effort to improve, such as by going to sleep at a reasonable hour and setting an alarm clock, then it is certainly appropriate to pray that his efforts should succeed. And this is true of all areas of religious life – once a person is making a genuine effort to succeed, then he – and others – can pray that those efforts should bring the desired results.
With this in mind, we can return to Yehoshua and the spies.
The Rebbe explains that Moshe sent the spies on a fact-finding mission. Their job was to objectively report the information, to tell what they saw, without giving any interpretation or offering an opinion based on that information. It was their job to determine the facts – and it was Moshe's job, and only Moshe's job, to reach decisions based on those facts. The spies' sin was arrogantly usurping Moshe's role. After they reported the facts, they gave their assessment about the prospects of capturing Eretz Yisrael – an assessment which wasn't theirs to make. They decided that their opinion was more important and more authoritative than that of Moshe Rabbenu – and this was their sin.
Before Moshe sent the spies, he was well aware of this danger. He knew of the natural tendency that people have to form opinions about things which are for the experts to decide, to assume they know better, to feel overly confident in their perspectives, their ideas and their impressions. But he could pray only for Yehoshua – because he saw that Yehoshua worked on his quality of humility. Upon seeing how Yehoshua made a conscious effort to remain humble, Moshe prayed that these efforts should succeed, that Yehoshua would remain humble and not overstep his bounds. Moshe could not pray for the other spies, because he did not see them working on their Midda (quality) of humility. He therefore prayed only for Yehoshua, his student who worked to live humbly, asking that these efforts should protect him from the arrogant tendency to give opinions that shouldn't be given.

