Post: An extremely strange interjection is made in the course of Moshe's description of the punishment for the chet hameraglim, in the first perek of Devarim:
Examine that pasuk in context to see that this is embedded in the chet hameraglim. But how could this be? Didn't Moshe lose out on entering the land because he hit the rock, or however you want to interpret his sin in the incident in which Moshe hit the rock. The chet hameraglim was in the beginning of the 40 years in the wilderness, while the smiting of the rock was at the end of the 40 years in the wilderness! And the placement makes it sound like it was this incident (and perhaps as reward for this incident) that caused the (eventual) succession of Yehoshua, when that was to come much later
I have my own answer, but first, let us examine Ibn Caspi expressing this difficulty:
"The Lord was also angry with me... There is to ask, did not this 'becoming angry' occur at the end of the forty years, by Mei Meriva, yet the events here happened at the beginning of the forty years! And more confounding than that is that in the war with Amalek, Hashem says to Moshe (Shemot 17:14), 'Write this for a memorial in the book, and rehearse it in the ears of Joshua: for I will utterly blot out the remembrance of Amalek from under heaven'. FOr there was hinted to him that he would wage the wars in Canaan. The answer is that there is no complaint or cause for wonder for the scholars of logic. For it is known that there are essential causes and incidental causes, and one thing can have many causes from many different sides, and I will not elaborate further, except that that which Hashem hinted to in the battles against Amalek, the resolution is in that which is stated [in Pirkei Avot, perek 3, Mishna 19], 'All is foreseen and yet free-will is given.' "
The idea behind this seems to be that Moshe's death outside the land was caused by many contributory factors; and further, that Hashem could know that Yehoshua would be the one to lead klal Yisrael into the land even before Moshe had acted in the manner that would cause him to not be that leader.
In this way, pasuk 37 and 38, above, can be part of the reaction to the chet hameraglim. Not only were the Israelites punished then, but Hashem was also angry with Moshe for that same sin, because of what the Jews sinned. It certainly does work.
I would resolve this in a different manner. Ain mukdam umeuchar baTorah. This means that the order of events in the Torah is not necessarily chronological, but topical. Here in particular, Moshe is giving a speech, summarizing the events in the wilderness. Moshe had just finished relating to them that Hashem had said that none of them, save Calev ben Yefuneh, would see the land of Israel. Then, topically, the fact that Moshe, as well, would not see the land, is relevant. And so, גַּם בִּי הִתְאַנַּף ה בִּגְלַלְכֶם. Not for this incident of the sin of the spies, and the people weeping. But for some separate incident and sin, namely the Mei Merivah. And so Moshe, too, could not enter the land. (That, as well, is why he did not mention Yehoshua as someone who would enter alongside Calev. There was a separate reason for Yehoshua to enter, which he would shortly get to.)
I see that this is the explicit approach of Ramban:
יאמר הנה חטאתיכם אשר עשיתם בעת ההיא במרגלים מנעו מכם הארץ הטובה ועוד הוספתם לחטוא בפעם אחרת עד שמנעתם גם אותי מלעבורWhile nothing is explicit in Rashi and Ibn Ezra, this seems so straightforward to me, and such a lack of chiddush -- and at the same time, if they had interpreted the pasuk like Ibn Caspi, they would have been compelled to comment in some manner -- that I think it somewhat likely that they implicitly interpret the pasuk in the same way as Ramban.
Still, Ibn Caspi creates a nice setup here. And the implication, even back when Yehoshua waged battle against Amalek early in the midbar, that he would be the one to lead the Israelites into Canaan still stands. I have a separate resolution, which I wrote up several years ago -- that the early incident with Moshe speaking to the rock, and the late incident, with Moshe hitting the rock, are really describing the same incident. And this incident occurred early on, in Refidim. This was prior to the sending of the spies. What shall we do with the pasuk (Bemidbar 20:1) that places the incident with hitting the rock in Kadesh / Midbar Tzin? That is just describing where Miriam was buried, not (necessarily) geographically placing the incident which is related in the pesukim which follow. And once again, the juxtaposition would not be due to chronology. Ain mukdam. Rather, it would be a topical juxtaposition, connecting the death of Miriam, such that she did not enter the land, with the death sentence for Aharon and Moshe, such that they would not enter the land. The point would be the transition of leadership and generation.