“And G-d was angry with me because of you” (D’varim 3:26). Rashi, based on the Sifre (Pinachas 135) elaborates on what Moshe meant when he told the nation that G-d was angry with him because of them: “[it was] on your behalf; you caused it to happen to me,’ as it says (in T’hillim 106:32), ‘and they caused [G-d to become] angry by Mei M’rivah, and it was bad for Moshe because of them.” Saying it was “on your behalf” and then adding “you caused it” indicates that something was done for the benefit of the nation, which led to something bad happening to Moshe. [That the intent of the word “l’ma’anchem” is “on your behalf” is evident from the choice of words in the verses (1:37 and 3:26), as well as from Rashi using another form of the word (“bish’vilchem,” a word he himself adds, as it does not appear in the Sifre) before saying that they caused it, and from his commentary on 4:21.] What was done on their behalf, and how did it cause Moshe to be punished? And what was Moshe trying to tell them?
The chain of events at Mei M’rivah (Bamidbar 20:2-13) was the nation arguing with Moshe because there was no water, G-d telling Moshe to speak to the rock, Moshe hitting the rock, and G-d becoming angry with Moshe. At first glance, it would seem that “on their behalf” therefore refers to alleviating their need for water, which led to Moshe being punished. However, why would the nation be blamed for Moshe’s sin, which according to Rashi (20:12) was hitting the rock rather than speaking to it? Since there was no water, it was necessary for some to be provided. Why would Moshe providing it differently than the way G-d had told him to be blamed on their need for water? Were they expected to die of thirst? How could they be considred the “cause” of Moshe’s punishment?
One possible answer (see Taz on D’varim 3:26 and Kli Yakar on 1:37) is that the nation needed to be “wowed” by the method the water was provided in order to improve their belief in G-d. Because Moshe hit the rock rather than speaking to it, there was a less impressive display of G-d’s abilities, which in turn had less of an impact on the nation. The instructions to speak to the rock were therefore “on their behalf,” i.e. to help them improve their perception of G-d and His abilities, and because Moshe hitting the rock instead of speaking to it minimized this benefit, he was punished. It was their need to believe in G-d more that necessitated speaking to the rock instead of hitting it, so they were considered the cause of Moshe’s punishment.
Another possible answer is based on the nation “arguing” with Moshe, rather than just bringing the issue to his attention. Because they were contentious, Moshe became upset with them, and his anger caused him to err, as it had on several other occasions (see Rashi on Bamidbar 31:21; one of the examples is Moshe getting angry at Mei M’rivah, and mistakenly hitting the rock because of it). However, this would not qualify as being “for their benefit,” as it was the way they dealt with Moshe that led to his becoming angry, not their need for water. True, their need for water that started the whole process, but his inability to enter the land was not based this need, only on how he responded to how they responded to this need, which was not to anyone’s benefit. (Besides, there would be no point in saying “and G-d got angry at me because you needed water”).
Several commentators (e.g. Mizrachi) understand Rashi to be saying that the nation caused Moshe to not be able to enter the land because they angered him, and in his anger he called them “rebels” (Bamidbar 20:9), for which he was punished. [Although this is similar to the previously mentioned possibility, it doesn’t include the last step (Moshe’s anger causing him to hit the rock rather than speaking to it).] And Rashi’s commentary on T’hillim (106:33) backs this up. However, Rashi (in Bamidbar) is quite clear that Moshe was punished for hitting the rock instead of speaking to it. How can Rashi here (and on T’hillim) say that Moshe’s sin was getting angry at the nation, if elsewhere he says it was for hitting the rock?
The context of our verse is Moshe’s intense (and repeated) supplication to G-d to allow him to enter the land. Therefore, when Moshe tells the nation that because of them he wasn’t able to, he wasn’t telling them why he was punished, but why his prayers weren’t answered (at least not the way he wanted them to be answered). What, you may ask, is the difference? Well, Moshe did call the nation “rebels,” which was problematic. And he did hit the rock, which was also problematic. G-d wasn’t happy with either, but one was primarily a sin between Moshe and the nation (getting angry with them), while the other was primarily a sin against G-d (not following His instructions properly). Both were reason enough to prevent Moshe from entering the land (see the commentators there for a discussion about why), but one was more directly connected to his role as a leader (because it meant not helping those he was leading reach a higher level), while the other was more directly connected to his personal growth (getting angry).
G-d could forgive him for not fully obeying His instructions, and could (theoretically) take away his leadership role without having to forbid him from entering the land. Moshe would not request that Y’hoshua should not become the leader if his time to take over had already arrived, as one king’s rule cannot extend into that of another (see Shabbos 30a, where Dovid was told he couldn’t delay things because it was time for Sh’lomo to take over). Moshe’s request was therefore likely only that he be allowed to live a bit longer so that he could “pass over and see the land” (D’varim 3:25), as a civilian. Y’hoshua would be the leader, and Moshe could die shortly afterwards; Moshe just wanted to see the land before he died. If his only sin was hitting the rock, perhaps G-d would have let him do so. However, because he also became angry with the nation, G-d wasn’t going to forgive him for having treated His chosen nation that way.
There are numerous explanations given for how G-d not letting Moshe enter the land was “on their behalf.” His burial place being opposite P’or provided constant atonement for their sin. His entering the land would have given the Mishkan/Temple permanence, preventing G-d’s wrath against the nation (when they sinned) from being taken out on “wood and stone” by destroying the Temple. His remaining in the desert will allow the generation that died there to eventually enter the land with him. Rashi may be adding another reason why G-d didn’t let Moshe enter the land. Even if He forgave him for hitting the rock, He didn’t forgive him for getting angry at the nation, teaching all future leaders that they must treat G-d’s children with respect and dignity. Moshe was relaying this message to the nation; G-d didn’t let me enter the land because of you, as on your behalf, because of how I reacted in your time of need, G-d remained angry with me, and did not let me enter the land.