The Rambam, in his introduction to his commentary on Pirkei Avot, explains that Moshe’s sin in hitting the rock was his outburst of anger : “And Moshe and Aharon gathered the assembly together before the rock, and he said unto them: ‘Hear now, ye rebels; are we to bring you forth water out of this rock?'”
“Moshe’s sin lay in his anger – his intemperate words to the people, “Listen to me, you rebels.” To be sure, in anyone else, this would have been considered a minor offence. However, the greater the person, the more exacting are the standards G-d sets. Moshe was not only a leader but the supreme role-model of the Israelites. Seeing his behavior, the people may have concluded that anger is permissible – or even that G-d was angry with them, which He was not.”
The Ramban rejects this explanation, his main argument being that the Torah does not say that Hashem punished Moshe for being angry, rather for disobeying the word of G-d, and for a lack of faith, as it says:
“And the LORD said unto Moshe and Aharon: ‘Because ye believed not in Me, to sanctify Me in the eyes of the children of Israel, therefore ye shall not bring this assembly into the land which I have given them.'”
“because ye rebelled against My commandment in the wilderness of Zin, in the strife of the congregation” 
The Maharal of Prague explains that indeed the anger of Moshe expressed in his harsh words to the people, as well as his action of hitting the rock, both stemmed from his shortcoming in emunah – faith.
How are we to understand the meaning of this “lack of faith” of Moshe? Surely Moshe believed that Hashem was able to bring forth water from the rock if spoken to, as he was commanded.
The Maharal, elsewhere in his writings, sheds new light on the concept of “emunah”, while discussing the emunah of Avraham Avinu.
In sefer Bereshit Avraham turns to Hashem and says:” ‘O Lord G-d, what wilt Thou give me, seeing I go hence childless, and he that shall be possessor of my house is Eliezer of Damascus?’ And Avram said: ‘Behold, to me Thou hast given no seed, and, lo, one born in my house is to be mine heir.'”In response to this question Hashem responds:
“And, behold, the word of the LORD came unto him, saying: ‘This man shall not be thine heir; but he that shall come forth out of thine own bowels shall be thine heir.’ And He took him outside, and said: ‘Look now toward heaven, and count the stars, if thou be able to count them’; and He said unto him: ‘So shall thy seed be.’ And he (Avraham) believed in the LORD; and He counted it to him for righteousness.”
Rashi comments on the last verse above: “and He accounted it to him as righteousness: The Holy One, blessed be He, accounted it to Abram as a merit and as righteousness for the faith that he believed in Him.”
The Ramban asks why this faith of Avraham is so commendable. Avraham was a prophet and why would he not believe his own prophecy?
In a lengthy answer, the Maharal explains the difference between a prophecy and a promise from Hashem. Though a full explanation of his answer is beyond the scope of this shiur, the essential quality of a heavenly promise is that it is given because of the nature of the righteous person and is entirely dependent on their righteousness. Any shortcoming on the side of the receiver will negate the realization of the promise. Avraham Avinu, in his words to Hashem about being childless, was expressing his awareness of the situation that he and Sarah did not have children. Not only that, but the way the reality appeared to Avraham, they were not going to have children either. This is expressed by Rashi’s words explaining what Hashem says to Avraham “‘And He took him outside’ He said to him, “Go out of your astrology,” for you have seen in the signs of the zodiac that you are not destined to have a son.” The implication of the concept of astrology here means that the order (divine order!) of the world at present is that Avraham will not have a child. Chazal even expressed this by saying that Avraham and Sarah lacked the bodily organs of reproduction! Hashem promises Avraham, that it is within his power to transform himself to a level beyond the present reality, a level where he and Sarah will have a child. The greatness of the faith of Avraham is that he believed that it was a possibility for him and Sarah to create such a transformation in themselves. Believing in a heavenly promise is believing in the ability of one’s self to live up to that reality, to change into someone destined for that promise.
When Hashem told Moshe to speak to the rock in front of the people, Hashem wanted to teach the people a lesson in Emunah. Not a lesson in faith of the ability of G-d to perform miracles, rather a lesson in faith of the ability of man to change their reality, in the ability to make the impossible, possible. Even a rock, hearing the desire of G-d, has the ability to hear and give forth its water. It was at this moment, a moment where there was no water for the people, a moment when people were losing sight of their cause and purpose for ever leaving Egypt, that Moshe was told to teach them that it was up to them to live up to their promise and destiny. Lack of faith that change is possible leads to anger and frustration and the lesson is lost. It was at this moment that the leadership of Moshe came to its end.
Shabbat Shalom, Avigdor
Rambam, Eight Chapters Introduction to Pirkei Avot, Chapter 4.
Ramban, Bamidbar 20:8.
Gur Aryeh Bamidbar 20:12.
Gevurot Hashem chapter 7.
Rashi Bereishit 15:5.
Yevamot 64 a-b.
“Indeed, Abram will have no son, but Abraham will have a son. Similarly, Sarai will not give birth, but Sarah will give birth. I will call you by another name, and your destiny will change.” – Rashiibid.
For had you spoken to the rock and it had given forth [water], I would have been sanctified in the eyes of the congregation. They would have said, “If this rock, which neither speaks nor hears, and does not require sustenance, fulfills the word of the Omnipresent, how much more should we!” Rashi Bamidbar 20:12.