Rashi's source seems to be Beitzah 16. However the Gemora there records an argument between Bais Hillel and Bais Shamai how to prepare for Shabbos. Given that we rule according to Bais Hillel, why is Rashi here quoting according to Bais Shamai?

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.
–
MichoelJan 29 '13 at 9:04

1

See Ramban who cites Rashi's source as Mechilta and then goes on to reject his explanation on the basis of Beis Hillel's opinion in the Gemora.
–
MichoelJan 29 '13 at 9:07

The Gur Aryeh on the verse says that Beit Hillel says that if you get something and you need it today, you don't have to wait until Shabbat, since you trust in G-d that He will provide for Shabbat.

Rashi here, the Gur Aryeh continues, is saying that even according to Beit Hillel, if you happen to come across it, but don't need it, wait until Shabbat to use it. That's why Rashi uses the term "Nizdamen", which means "chance upon" (Translation from here):

and this is its interpretation: Pay attention to always remember the Sabbath day, so that if you chance upon a beautiful thing, you shall prepare it for the Sabbath

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.

The Mishnah Brurah (250:2) quotes many poskim who say that even Hilel agrees that for a normal person it is better to do it according to Shamai's way, but Hilel himself did it his own way in order to strengthen his trust in G-d, but for an ordinary person he agrees he shouldn't do it.