Perhaps the Torah is reminding us that Miriam slipped up despite seeing with her own eyes the role Moshe played in bringing about the redemption from Egypt. If such an error could be made by Miriam, how much more so must we be on guard (see Ramban, R' Bachyei).
Rashbam explains that the Torah is not addressing what Miriam did, but rather is reminding us what Hashem did on her behalf. Even though Bnei Yisrael was “b’derech b’tzeischem m’Mitzrayim” and anxious to keep moving on the road away from Egypt toward Eretz Yisrael, the entire camp waited on behalf of Miriam and did not travel until her leprosy was cured. Chasam Sofer makes a similar point, contrasting the command with respect to Amalek, “Zachor eis asher asah lecha Amalek,” where we are told to remember their deeds, with the command here, “Zachor eis asher asah Hashem Elokecha,” where the focus is on G-d’s chessed and not Miriam’s wrongdoing.
The Midrash gives a beautiful explanation:
למה הדבר דומה? למלך שעלה מן המלחמה קילסה אותו מטרונה.
אמר המלך: תיקרי אומן של סנקליטור. לאחר ימים התחילה לערב אוננא של מלך.
אמר המלך: כך עשית?!
כך, בשעה שעשה הקב"ה מלחמת הים אמרה מרים שירה ונקראת נביאה, שנאמר: (שמות טו) ותקח מרים הנביאה. כיון, שאמרה לשון הרע על אחיה, אמר הקב"ה תיטרד למטלון! שנאמר: (במדבר יב) ותסגר מרים:
According to the Midrash, “b’derech b’tzeischem m’Mitzrayim” is not speaking about the episode of Miriam’s lashon ha’ra. It is speaking about Miriam singing shirah at Yam Suf. The Midrash is telling us that when we remember what Miriam did wrong, it must be in context of what Miriam did right; only then do we have the complete picture. Why was Miriam judged so harshly for just a few words that she said with the best of intentions in private to Aharon? Because Miriam had the wonderful gift of being able to use words properly and sing to Hashem. Someone who is given a special talent, someone who can sing shirah, is held to a different standard than those who do not have that special gift.