In P' VaYelech Moshe charges Yehoshua with the mission of conquering Eretz Yisrael, but then the Torah switches gears and discusses Moshe's nevuah that Bnei Yisrael will end up serving idolatry, will ultimately do teshuvah, and then discusses Moshe's writing sifrei Torah. Finally, Moshe again (31: 23) speaks to Yehoshua, charging him, "Chazak v'amatz..." Why interrupt the narrative concerning the appointment of Yehoshua with these other topics?
The Oznayim laTorah offers two answers. Firstly, Moshe was telling Yehoshua not to think his job was only to be a great general, a great administrator, a great political leader. The Torah reiterates the bris of teshuvah and the kesivas sefer Torah to demonstrate the responsibility of leadership to promote Torah -- that was Yehoshua's primary mission. Secondly, Moshe was preparing the nation to accept Yehoshua. As much as we respect and admire giants like R' Akiva Eiger, the Chasam Sofer, etc. it pays to remember that there are enough stories of gedolim who, in their own time, were literally run out of their towns by elements of the populace. Yiftach b'doro k'Shmuel b'doro -- the respect accorded to the greatest giants in Torah in our time is sadly not universal. Moshe had to ensure that Yehoshu'a "ba'alei batim" would be committed to the same ideals as he was, and therefore before charging Yehoshua with the task of leadership, he reminded the people of the commitment that was necessary on their part.