The first verse after Moshe’s charge is 31:9 that Moshe gave the Torah to the priests and the elders. Why was this verse recorded after Moshe's charge in 31:7,8? A possible answer is that 31:9 contains two ideas. One, the deposition of the Torah and two, Moshe is reminding Yehoshua that there are other leaders, the priests and the elders, who can help him. In 31:8, as part of his charge to Yehoshua, Moshe told Yehoshua that he was not alone since G-d was with him, and then in 31:9 Moshe was indicating to Yehoshua that also the priests and elders were with him. This explains the reference to the elders in 31:9 who did not have to be mentioned if the issue was only the storage of the Torah, but they did have to be referred to if the goal was to mention other leaders of the people. Thus, on the second occasion when Moshe gives the Torah over, 31:26, the elders are not mentioned since this was after Yehoshua had been fully appointed.
Afterwards, 31:10-13 records the law of hakhel, that every seven years all the people were to gather together to hear the Torah being read. Why did Moshe wait until after passing the leadership to Yehoshua to tell the people about the laws of hakhel? The goal of the ceremony was to increase the people's fear of G-d in the future, and hence Moshe was telling Yehoshua that this ceremony would help him in dealing with the people. Due to the ceremony, there would be a greater chance that the people would continue to listen to Yehoshua in the future, and maybe this would boost Yehoshua's confidence.
Another possible connection between hakhel and the appointment of Yehoshua is that many have argued that the hakhel ceremony was to re-create the giving of the Torah at Mount Sinai, see for example Jacobson, 1986, pp. 211,212. The basis for this supposition is from the Rambam, Laws of Festival Offerings, 3:6 and the use of the word hakhel in Devarim 4:10 and 18:16. Also, 31:12 records that the point of the gathering every seven years was experiential, to instill the fear of G-d into the people, which was also one of the purposes by the Decalogue, Shemot 20:17. Furthermore, Devarim 18:15-22 record that Moshe told the people that in the future they would have prophets who they would have to accept. Moshe explained that their future acceptance was based on their acceptance of Moshe at the time of the Decalogue, when they asked Moshe to speak to G-d since they were afraid of G-d continuing to speak to them. Accordingly, maybe Moshe mentioned the laws of hakhel as part of the process of appointing Yehoshua to be the next leader of the people to remind the people of their actions by Decalogue, the source of authority for all prophets. Furthermore, just as hakhel symbolized a re-enactment of the Decalogue, so too more prophets could be “re-created.” (Note, just as the hakhel was only a re-enactment of the giving of the Torah and not equal to the actual event, so too the future prophets who would be successors to Moshe would never be equal to Moshe.) Thus, the reference to the laws of hakhel might have been part of Moshe’s attempt to generate support for Yehoshua from the people or to increase Yehoshua's confidence.
After the laws of hakhel, G-d told Moshe to bring Yehoshua into the ohel moed where G-d would speak to him, 31:14. Ramban (on 31:19) explains that the idea was for G-d to make Yehoshua a prophet in Moshe’s lifetime. 31:15 records that the cloud of G-d, a demonstration of G-d’s powers, descended upon the entrance of the ohel moed. This showed the people that G-d was talking to Yehoshua which showed G-d’s support for Yehoshua as a prophet.
In addition, the appearance of the cloud of G-d was part of the 3rd stage of the covenantal process in the book of Devarim, see our discussion on Shemot 24 "The covenantal process." By every covenant there is a revelation from G-d (see Rashbam on Shemot 33:18), and the revelation by the covenant on the plains of Moav was the appearance of the cloud of G-d. The cloud showed the people that G-d approved of the appointment of Yehoshua to be their leader and it was the revelation that occurs by every covenant.
Afterwards, 31:16-22 records that G-d told Moshe about the song that was the witness of the covenant. When G-d finished telling Moshe the song, 31:22 records that G-d told Moshe to write the song down and teach it to the Jewish people, which means that Moshe left the tent. This implies that Yehoshua was left alone with G-d, and 31:23 records that G-d charged Yehoshua to be the next leader of the people, see Rashi, Ramban and Seforno on 31:23.
Why was Yehoshua with Moshe when G-d was just speaking to Moshe in 31:16-22? Why did G-d not charge Yehoshua immediately after the cloud of G-d appeared in 31:15? Or, in other words, why does 31:23 not follow 31:15? Ibn Ezra (on 31:16) is so bothered by this question that he argues that this is another example of the Torah recording events not in their chronological order, as he claims that 31:23 occurred immediately after 31:15. I rarely like this approach, and instead Hoffmann (1961, p. 566) suggests a reasonable answer.
Hoffmann explains that Yehoshua was standing next to Moshe when the cloud of G-d descended and when G-d spoke to Moshe. G-d first spoke to both Moshe and Yehoshua together, 31:16-22 and then to Yehoshua alone, as a way of passing Moshe’s majesty to Yehoshua, 31:23. The idea is that it was not enough for G-d to have just spoken to Yehoshua alone, rather the people also had to see that G-d spoke to Moshe and Yehoshua together.
Accordingly, G-d’s charge to Yehoshua in 31:23 culminated a five part process to enhance Yehoshua’s leadership. First, Yehoshua was told that he would have assistance from the elders, 31:9, and then the laws of hakhel were mentioned, 31:10-13. Afterwards, the cloud of G-d appeared over the tent, 31:14,15, then G-d spoke to Moshe and Yehoshua together, 31:16-22 and lastly G-d spoke to Yehoshua alone, 31:23. Moshe’s charge to Yehoshua in 31:7 started this process and G-d’s charge to Yehoshua in 31:23 ended this process.
Why was there such a lengthy process? Presumably it was because Yehoshua had a very difficult task in following Moshe. Moshe had been the leader of the people for 40 years, and had done things no human would ever duplicate. It would have been only natural for the people to withhold their support for Yehoshua, as capable as he was, after having had Moshe as their leader. Thus, Moshe himself passed the leadership to Yehoshua, and G-d also raised Yehoshua’s status by making him equal to Moshe in hearing (and maybe writing, see Ramban on 31:19) the last message that G-d spoke to Moshe. G-d was not just establishing Yehoshua as a prophet but also showing the people that he was a worthy successor to Moshe.
Bibliography:
Hoffmann, David Tzvi (1843-1921), 1961, Commentary on Deuteronomy, translated by Tzvi Har-Shefer, Tel Aviv: Nezach.
Hoffmann, David Tzvi (1843-1921), 1961, Commentary on Deuteronomy, translated by Tzvi Har-Shefer, Tel Aviv: Nezach.
Jacobson, B. S. 1986, Meditations on the Torah, Hebrew, Tel Aviv: Sinai Publishing.