It states (13:16) ַֻׁעיְהוֹש נוּן בִּן ֵַׁעלְהוֹש ֶׁהמֹש וַיִּקְרָא, "Moshe called Hosheia bin Nun, Yehoshua." He added a ד"יו to his name, and ֵַׁעהוֹש became ַֻׁעיְהוֹש, placing Hashem's name ה"י at the beginning of his name.
Rashi writes that by doing so, Moshe was davening for him. Rashi writes, ה"י ,עליו התפלל מרגלים מעצת יושיעך, "He davened for him, that ה"י, Hashem, should save him (ֵׁעהוֹש) from the counsel of the malachim." This tefillah helped Yehoshua, and he didn't join with the grave error and aveirah that the Miraglim committed.
The Midrash (Bamidbar rabba 16:9), however, explains that it wasn't a tefillah, but rather a prophecy. Moshe said a prophecy יושיעך ה"י מרגלים מעצת, Hashem will certainly save you from the Miraglim's counsel.
The Yeitav Lev explains that Moshe knew that Hashem would protect Yehoshua from this error and aveirah of the Miraglim because Yehoshua had a strong desire to do Hashem's will. When one desires to serve Hashem, Hashem helps him. This is how Moshe knew for certain that יושיעך ה"י, Hashem will help Yehoshua pass the test.
To explain, the Yeitav Lev quotes the Gemara (Succah 52b) which says, "The yetzer hara of man becomes stronger every day, and if Hakadosh Baruch Hu won't help him, he won't succeed over the yetzer hara." The Yeitav Lev quotes his grandfather, the Yismach Moshe zt'l, who discusses this Gemara and asks: Why does Hashem only help the tzaddikim to succeed over the yetzer hara? Why doesn’t Hashem also help the resha'im conquer their yetzer hara? Furthermore, if the tzaddikim succeed in the battle with the yetzer hara solely because Hashem helps them, what makes them better than the resha'im? The resha'im would also do good, if Hashem would help them, as well!
The Yismach Moshe explains that Hashem helps tzaddikim because they genuinely desire to do good. They battle with the yetzer hara, they do as much as they can, and therefore, Hashem helps them. As Chazal say, אותו מסייעין לטהר הבא, when a person tries to be pure, Hashem helps him. Also, it states (Shemos 25:3) ָּוְחָֽד ַלְת מַשּׂ ָאוֹ תַּחַת רֹבֵץ ָשֹׂנַֽאֲך חֲמוֹר ת ִרְאֶה כִּֽי עִמּֽוֹ תַּֽע ֲזֹב ע ָזֹב לוֹ מֵֽע ֲזֹב, "If you see your enemy's donkey lying under its burden would you refrain from helping him? You shall surely help along with him." On the words תַּֽע ֲזֹב ע ָזֹב עִמּֽוֹ, "You shall surely help along with him," Chazal explain that you are only obligated to help your fellow man if he is trying to help himself. If he is trying to lift the animal, you must help him. But if he doesn't do anything, and he says, "You have a mitzvah to help me," you aren't obligated to help him. This is the way Hashem acts with us. If we try to help ourselves, Hashem helps us. However, if we are lazy and don't help ourselves, and we don't try to overcome the yetzer hara, Hashem doesn’t come to help us.
Moshe knew that Yehoshua’s real desire was to do Hashem's will, so he was able to testify with confidence מרגלים מעצת יושיעך ה"י, Hashem will undoubtedly help him, and he won't fail the test of the Miraglim.
It states (15:39) עֵינֵיכֶם וְאַחֲרֵי לְב ַבְכֶם אַחֲרֵי תָתוּרוּ וְלֹא אַחֲר ֵיהֶם זֹנִים אַת ֶּם ֶׁראֲש, "You shall not wander after your hearts and after your eyes after which you are going astray." From these words, we understand that the nature of man is to stray after his eyes, so how can the Torah demand from us עֵינֵיכֶם וְאַחֲרֵי ... תָתוּרוּ וְלֹא, that we shouldn't stay after the eyes? How can we be obligated to go against the nature ingrained in us? The Chidushei HaRim (Sefer HaZechus) answers that although people's innate nature is to stray after the eyes, a person also has spirituality in him, which inspires him to guard his eyes and to search to do Hashem's will. He now has free choice – to either listen to the inspiration of his holiness or to follow the natural pull of his nature – and he can choose wisely, according to Hashem's will. The Chidushei HaRim explains, "This pasuk [obligating us to guard our eyes] is a guarantee from Hashem yisbarach that there is a spark of holiness in every Yid, which enables us to overcome the yetzer hara and to not listen to the drawing of the heart and eyes." And, as we explained, if he chooses to do good, Hashem will help him.
The Torah (15:41) writes (and we say it at the end of Shema), מ ִצְר ַיִם מֵאֶרֶץ אֶתְכֶם הוֹצ ֵאתִי ֶׁראֲש א ֱלֹק ֵיכֶם 'ה אֲנִי א ֱלֹק ֵיכֶם 'ה אֲנִי לֵאלֹקִים לָכֶם לִה ְיוֹת, "I am Hashem, your G-d, Who took you out of the land of Mitzrayim to be your G-d; I am the Hashem, your G-d." The Gemara Menachos (44a) states that it says twice in this pasuk א ֱלֹק ֵיכֶם 'ה אֲנִי. With the double א ֱלֹק ֵיכֶם 'ה אֲנִי, Hashem is saying, "In the future, I will punish and I will give reward." The Gemara (ibid.) tells of a Torah scholar who almost committed a severe aveirah, but his tzitzis hit him in the face to stop him. At that time, he said this lesson: there is punishment and there is reward, and this realization helped him overcome the yetzer hara.
The Chidushei HaRim elaborated on this lesson some more. The first time it states אֲנִי א ֱלֹק ֵיכֶם 'ה in this pasuk, it refers to the miracles that Hashem performed for us at yetzias Mitzrayim. As it states הוֹצ ֵאתִי ֶׁראֲש א ֱלֹק ֵיכֶם 'ה אֲנִי מ ִצְר ַיִם מֵאֶרֶץ אֶתְכֶם, "I am Hashem, your G-d, Who took you out of the land of Mitzrayim." The purpose was לֵאלֹקִים לָכֶם לִה ְיוֹת, so Hashem will be our G-d. The pasuk concludes, 'ה אֲנִי א ֱלֹק ֵיכֶם. The second time it states א ֱלֹק ֵיכֶם 'ה אֲנִי, it is referring to our times. When a person desires to serve Hashem, Hashem will perform miracles to help him succeed.
The Chidushei HaRim's words are as follows: מצרים מיציאת והנפלאות הניסים כל מתעורר 'ית 'ה לעבוד שרוצה לאדם ועזר לסיוע, "All the miracles and wonders of yetzias Mitzrayim are aroused to help the person who desires to serve Hashem." It is up to him to desire, to try, and then Hashem will help him, even in miraculous ways. He can merit miracles similar to those that occurred at yetzias Mitzrayim, to help him do Hashem's will. It all begins with his desire to do good.