I upvoted Baal Shemot Tovot's answer:
I've heard from Rabbi Shalom Carmy that the reference to Beitzah is actually a printer's error and Rashi got this from this Mechilta D'Rabbi Yishmael, where it remains undisputed.
Michoel, in the comments to that post has a strong question:
I am not sure how this answers the question. At the end of the day there still remains a dispute in the Gemora between Beis Shaima and Beis Hillel, and we should therefore rule like Beis Hillel.
This answer thus requires further elaboration. As I explain on my blog, though modified a bit here:
I think that one can put forth the following points.
Look at the context. By this, I mean look at the other Rashis in the perek, and see how many of them are from the Mechilta. See this in Mekorei Rashi, or alternatively, from Chabad's Tanach. A taste, listing the dibbur hamatchil and then the source, from pasuk 1 and on:
- וידבר א-להים: Mechilta
- את כל הדברים האלה: Mechilta
- לאמר: Mechilta
- אשר הוצאתיך מארץ מצרים: Shemot Rabba (though note that the composition of the entire work is 11th or 12 century); Mekorei Rashi also lists Devarim Rabba, which is indeed earlier.
- מבית עבדים: Shemot Rabba; same caveat. Mekorei Rashi gives Mechilta.
- לא יהיה לך: Mechilta
- א-להים אחרים: Mechilta
- על פני: Mechilta
What Rashi is doing in this perek is a running commentary, primarily adapted from the Mechilta. He is channeling the Mechilta for us. As such, if Mechilta has a comment of the sort Rashi would bring (uleaggada hameyashevet divrei hamikra), we would expect him to bring it, even if elsewhere, in a gemara somewhere, there is a dispute, and we rule against the position.
Further, this is not the only place Rashi brings a midrash halacha which is against the paskened halacha. Some modern meforshei Rashi take note of this, and explain that Rashi will bring forth such a midrash if he feels that it is more along the lines of peshat, since his goal is a peshat-oriented commentary, as adopted / adapted from midrash. So indeed, Rashi can and will cite midrash which will be against decided halacha, on occasion.