We know that Hashem rewards and punishes מִדָּה כְּנֶגֶד מִדָּה - Measure for Measure, in accordance with the deed. How was banning Moshe from entering Eretz Yisrael a suitable punishment for hitting the rock instead of talking to it?
The Chasam Sofer offers an explanation. He quotes Chazal who teach that if Moshe Rabbeinu had entered Eretz Yisrael, the Yidden would never have stooped to idol worship, and the Beis Hamikdash would not have been destroyed.
The Chasam Sofer points out that only the first Beis Hamikdash was destroyed due to idol worship. The sin that brought about the destruction of the second Beis Hamikdash was שִׂנְאַת חִנָּם - baseless hatred. How would Moshe's entry into Eretz Yisrael have prevented the Beis Hamikdash from being destroyed by sinas chinam?
He answers that by talking to the rock, Moshe would have demonstrated to Klal Yisrael the tremendous power of speech. Even many years later, Klal Yisrael would not stoop to speaking negatively about one another. They would never come to hate another Yid and the Beis Hamikdash would not be destroyed.
