In parshat Chukat, we see that it was Moshe who hit the rock instead of speaking to it, as G-d had commanded him. Yet, Aharon was punished with dying before entering the land of Israel, receiving the same punishment as Moshe. What did he (not) do to deserve this punishment?
The Midrash Tanchuma ask the question:
See Midrash Tanchuma (see here paragraph 10 (Yod)):
וַיֹּאמֶר ה' אֶל מֹשֶׁה וְאֶל אַהֲרֹן יַעַן לֹא הֶאֱמַנְתֶּם בִּי. לָמָּה נֶעֱנַשׁ אַהֲרֹן.
The Midrash later says that Moshe itself asked this:
אַף כָּךְ אָמַר מֹשֶׁה לִפְנֵי הַקָּדוֹשׁ בָּרוּךְ הוּא, רִבּוֹנוֹ שֶׁל עוֹלָם, אֲנִי הִקְפַּדְתִּי, אַהֲרֹן מֶה חָטָא.
I have read forward, but the paragraph seems to say that Moshe was right (at least I not perceived the answer). After the reading of Yalkut Shim'oni we can understand easily the Tanchuma.
In Yalkut Shim'oni, Siman 764 we found the same question followed by an answer (which is perhaps alluded in the Tanchuma)
יען לא האמנתם - היה לו לומר: ואמר: לא האמנתם בי, אהרן מה חטא? מכאן שהמטפל לעובר עבירה כעובר עבירה. והיה אהרן יכול לומר אני לא חטאתי, אלא שתק וכבש כחו ולא למד על עצמו סניגוריא. ומשה מקלסו, שנאמר: האומר לאביו ולאמו לא ראיתיו - לא עמד לומר עשה בשביל אבא בשביל אמא שלא תכנס שכולה בג' בניה.
"Because you don't trust in me...": We learn here that the subordinate to (who follows) one who transgress would itself be viewed as transgressing. But despite that, Aharon could have told "I did not transgress" But he (Aharon) refrain itself and had not defend himself. And Moshe congratulates him.
After the reading of the Yalkut, we can understand the Tanchuma. The Midrash start wih an allegory, Aharon is the neighbor of the indebted (Moshe) and sustained damage because because of its proximity . And Moshe is the one who protested against the punishment of Aharon (the same protestation described in Yalkut as a possibly answer for Aharon) and Moshe is complimented because He stood and fought for his brother.
The combination of both is marvelous. Aharon was not defending himself, but Moshe was defending Aharon. Both are commended for their conduct.
Anyway, the punishment is for its association in this situation. It is a bit similar to the known "Oy larasha Oy lishcheno"
Aharon was punished because he did not act in conformity with his defining middah of Oheiv Shalom V'Rodeif Shalom by restraining Moshe's anger and ensuring that the dispute over the water shortage would be brought to a happy ending. According to the peshat, as recognized by the Rashbam, Chizkuni and Kli Yakar, the Mateh at Kadesh was the Mateh Aharon discussed in Parashas Korach, not the Mateh Elokim with which Moshe brought forth water by hitting the Tzur at Maseh U'Merivah in Parashas Beshalach. (The presence of the Mateh Aharon here explains why Hashem commanded that Aharon be present at Kadesh, but did not issue a similar command at Masah.) As set forth in Parashas Korach, the purpose of the Mateh Aharon was to tamp down disputes between people before they became complaints against Hashem, resulting in the deaths of the complainers. Had Moshe followed Hashem's instructions at Kadesh, including speaking to the sela and personally providing water to the Edah and their animals ("V'Hishkisa Es HaEdah V'Es Bieeram"), the dispute (which did not involve Hashem at all) would have ended happily. By hitting the sela, he brought forth a flood in which people and animals took for themselves ("VaTeisht HaEdah U'Vieeram"). The result was lingering hard feelings that burgeoned into a much serious dispute a few months later (the dispute with the Nechash Nechoshes) in which the nation complained against Elokim and slandered the Mahn. That dispute resulted in the deaths of "Am Rav MiYisrael" who should have entered Eretz Yisrael. Those deaths would not have happened had Moshe and Aharon acted in conformity with Hashem's instructions at Kadesh.
Your question assumes that hitting the rock was the sin. I happen to believe that the sin was falling on their faces in front of the nation and not standing up for G-d, which was an (in)action perpetrated by both. I cannot explain the entire theory here; read these source sheets: http://www.sefaria.org/sheets/tags/Moshe%20and%20Aharon's%20Real%20Sin.