This question already has an answer here:
-The Talmud says, in two places, "He who reports a saying in the name of its author brings deliverance to the world." [Megillah 15a; Chullin 104b]
-The Talmud is very careful to always attribute its teachings. The above is credited to Rabbi Elazar.
-Rashi and the Rambam did not generally attribute teachings in their writings. But then, their purpose was to summarize, to compile, to organize. They could have cited sources in footnotes, but didn't.
-Many later commentators cite Rashi and the Rambam as if they were the originators of teachings. For example: "See Rashi on Exodus 4:3". They could have looked up the original in Talmud or the midrashim, and credited it, but didn't.
-So why did Rashi, the Rambam, and many later commentators not follow the Talmudic injunction?
(If someone wishes to argue: "All rabbis quote their masters and it all goes back to Moses anyway, so why bother with names?", then why did the Talmud report that teaching and follow it scrupulously in every single page?)