When Yom Tov is followed by Shabbat, it is a mitzva to set aside an eruv tavshilin before Yom Tov. Doing so makes it permissible to cook and bake on Yom Tov for Shabbat. The eruv consists of food that is prepared before Yom Tov for Shabbat. It is called an eruv (literally “merging”) because it merges or joins together the food of Yom Tov and the food of Shabbat. Once the eruv has been set aside, then just as it is permissible to bake and cook on Yom Tov for Yom Tov purposes, it becomes permissible to bake and cook on Yom Tov for Shabbat purposes as well. True, on the Torah level it is permitted to cook on Yom Tov for Shabbat even without an eruv, but the Sages prohibited doing so, in order to preserve the honor and dignity of both Yom Tov and Shabbat (Beitza 15b).
The honor of Yom Tov: The Sages were concerned that were it permissible to cook on Yom Tov for Shabbat unconditionally, people would also cook on Yom Tov for the upcoming week, thus transgressing a Torah prohibition. Therefore, the Sages permitted cooking on Yom Tov for Shabbat only for those who began the Shabbat preparation before Yom Tov by setting aside an eruv tavshilin. Then any preparation for Shabbat undertaken on Yom Tov is simply a continuation of what was begun before Yom Tov. Once people are aware that without an eruv tavshilin they may not cook on Yom Tov for Shabbat, they will realize that it is certainly prohibited to cook on Yom Tov for the upcoming week (R. Ashi’s opinion in the Gemara).
The honor of Shabbat: The Sages were concerned that because of the focus on preparing Yom Tov meals, people might forget that Shabbat was the next day, and would finish all the good food on Yom Tov. Therefore, the Sages required setting aside an eruv tavshilin before Yom Tov, which would help people remember on Yom Tov to leave some good food for Shabbat (Rava’s opinion in the Gemara). Since an eruv tavshilin both honors Yom Tov and ensures that Shabbat will not be forgotten, it is a mitzva for every Jew to set one aside.
One must make sure to complete cooking for Shabbat before shki’a on Friday, so that in theory, the food being cooked could be eaten on Yom Tov if unexpected guests drop by.
In practice, most poskim follow Rabba (Rif, Rosh, Ramban, Rashba, Ran, Smag, Hagahot Maimoniyot), while some follow R. Ḥisda (Ha-ma’or, Rabbeinu Ḥananel, Rabbeinu Ephraim, Ritzba). Rambam incorporates elements of both positions – Rabba’s ho’il as well as R. Ḥisda’s concern (Beit Yosef 527:1).
Tosafot (Pesaḥim 46b s.v. “Rabba”), Rashba, and Mordechai state that according to Rabba, if one cooks on Yom Tov close to shki’a, when it is impossible that guests will benefit from his cooking, he transgresses a Torah prohibition. Based on this, Magen Avraham (beginning of §527) comments that even if one has set aside an eruv, he must be careful to finish cooking on Yom Tov while there is still plenty of daylight, so that were guests to arrive they would be able to enjoy the food. This is also the opinion of Eliya Rabba 527:2; SAH ad loc. 1; Ḥemed Moshe ad loc. 1; MB ad loc. 2; and Ben Ish Ḥai, Tzav §6. Pri Megadim is inclined this way as well.
In contrast, many poskim maintain that one may cook until shki’a (Radbaz 2:668; Rishon Le-Tziyon, Beitza 2b; Sho’el U-meshiv, Mahadura Tinyana 2:10). They are relying on the Rishonim who follow R. Ḥisda completely (so ho’il is not taken into account). They are also relying on Rambam who feels that Rabba agrees with R. Ḥisda, as he follows Rabba in one place (Laws of Yom Tov 1:15) and R. Ḥisda in another (6:1). Pri Megadim (Hilkhot Yom Tov, Petiḥa 1:17) and AHS (527:3) point out that this accords with the common custom to cook for Shabbat on Yom Tov up until shki’a.
At first glance, there seems to be a problem. Since most Rishonim believe that the halakha follows Rabba, and in their opinion the prohibition of cooking on Yom Tov for afterward is a Torah prohibition, how can we disregard their position by cooking until shki’a? Furthermore, how is it possible that all the Rishonim who follow Rabba do not specifically admonish people to make sure to finish cooking earlier in the day, so that the food could be eaten before shki’a? We can suggest that in fact, the food in question will almost always be cooked enough to be edible on Yom Tov. After all, we can assume that the cooking begins before lighting Shabbat candles, since people want to be able to stir the food and add the appropriate spices. Therefore, they are certainly putting the food on the fire a significant amount of time before shki’a. Additionally, those Rishonim who follow Rabba may think that the opposing opinion of R. Ḥisda (that ho’il is not taken into account) is significant enough to define this case as one of uncertainty. Besides, whether bein ha-shmashot is considered day or night is also uncertain. Accordingly, as long as the food will be ready during bein ha-shmashot, we may regard the case as a twofold doubt and be lenient. In practice, some say that when necessary, if one did not manage to cook early, he may cook until shki’a (BHL 527:1 s.v. “ve-al”; R. Mordechai Eliyahu, Ma’amar Mordechai, p. 125; SSK 2:14; Ḥazon Ovadia, p. 278). R. Ben-Zion Abba Shaul (Or Le-Tziyon 3:22:3) is stringent, but makes an excellent suggestion: he writes that a person may add an egg, which cooks in a matter of minutes, to the food he wishes to cook. Since it is permissible to do melakha in extra quantities (marbeh be-shi’urim), he may then add anything else to the pot, as long as all the food is added to the pot before it is put on the fire.