Melachos which are permitted on Yom Tov are only allowed to be done for benefit on that day, not to prepare for another day. When Shabbos follows Yom Tov, adherence to this halacha would negate the ability to cook for Shabbos. Chazal therefore instituted the idea of an eiruv tavshilin on Erev Yom Tov, which allows cooking to be done on Yom Tov for Shabbos. There are two views in the Gemara about the way an eiruv tavshilin works. According to one opinion, cooking on Yom Tov for another day is only forbidden mid’rabonon if there is enough time before the end of Yom Tov to serve the food to a guest who would suddenly drop by for a meal. Given this, Chazal waived their prohibition and allowed cooking for Shabbos (as long as time is left for the food to be ready on Friday/Yom Tov) when an eiruv is in place. According to the other opinion, although cooking on Yom Tov for a weekday is forbidden min haTorah, cooking for Shabbos is not. Chazal decreed that an eiruv must be made, though, to serve as a reminder not to cook on Yom Tov for a weekday. According to this opinion, cooking may be done on Friday--even close to sunset, and even if the food will not be edible on Yom Tov. Mishnah Berurah rules that one should be stringent and make sure that any food which was cooked for Shabbos is edible on Yom Tov. Under pressing circumstances, even if the food will not be ready on Yom Tov, one may be lenient and cook.
[שו"ע תקכז, א, משנ"ב א ו־ג, וביה"ל ד"ה ועל]