Yet at an earlier juncture Moses had been told to hit the rock. So what was the sin he now committed?
The Yalkut Shim’oni compares Moses to a teacher. If a pupil needs a rebuke, it all depends, says the Yalkut, on his age and stage of development.
With a young pupil who doesn’t yet know how to reason things out, the teacher is entitled to smack him; but with an older pupil, hitting is unlikely to get anywhere and the teacher should speak to him.
Moses was not punished because the rock had done anything wrong, but because as a leader he was dealing with the people in an inappropriate way. By this stage they had matured sufficiently for a verbal rebuke.