The basis for the permissibility of doing melakha on Yom Tov is to prepare and improve dishes and thereby enhance the simḥa of the festival. The taste of fresh bread from the oven cannot be compared to the taste of day-old bread; the taste of freshly fried schnitzel or freshly baked potatoes cannot be compared to that of schnitzel or potatoes prepared yesterday. Food made today – whether cooked, fried, or baked – is generally better than food made yesterday. Since food may be prepared on Yom Tov in order to make the festival more enjoyable, one need not try to prepare everything beforehand. Even for the first night of Yom Tov, the cooking may be done after Yom Tov begins. One might think that this should not be the case, since if one were to cook that food shortly before the start of the festival, it would be almost as fresh and tasty. Nevertheless, we do not draw distinctions between the meals, and any food that is better fresh may be cooked on Yom Tov. Even nowadays, when refrigerators preserve cooked and baked food better than anything available to the Sages, the permissibility remains, because the food on its own, without the aid of appliances, is better when it is made shortly before it is served.
All this applies to food whose taste is somewhat compromised if prepared a day in advance. In contrast, food whose taste is not impaired over the course of a day must be prepared before Yom Tov. For example, if one wants to have ice cream or compote on Yom Tov, he must prepare them in advance, since doing so does not affect their flavor at all. Nevertheless, if he did not prepare them before Yom Tov, he may prepare them on Yom Tov with a shinui. The shinui does not have to be a major one, as the point is just to remember that it is Yom Tov, so that one does not end up doing forbidden melakha (Levush 504:1). For example, if one generally prepares the food directly on the table, he may put down a tablecloth or a tray and prepare the food on them. If one could not prepare the food before Yom Tov due to circumstances beyond his control, he may prepare it normally on Yom Tov, with no need for a shinui (MB 505:10; SHT ad loc. 8).
This law applies to all melakhot like Borer which are permitted on Yom Tov for purposes of food preparation. If one can do them before Yom Tov without impairing the food, he must do so. If he did not prepare them beforehand, he may do so on Yom Tov with a shinui.
SA 495:1 appears to rule leniently, while Rema is stringent. Indeed, all the Ashkenazic Aḥaronim are stringent about this issue. Many Sephardic poskim are stringent as well; see Shiyarei Knesset Ha-gedola (OḤ 495, Hagahot Beit Yosef 4-6, adding that SA is not explicitly lenient), Pri Ḥadash (495:1), Birkei Yosef (495:2), and Ḥazon Ovadia (Yom Tov, p. 8). In contrast, Or Le-Tziyon (3:19 n. 1) allows Sephardim to be lenient even le-khatḥila. Since all Ashkenazic poskim and many Sephardic ones are stringent, that is the ruling written above. If one did not prepare the food before Yom Tov, some are stringent (Or Zaru’a and Maharil, as cited in Darkhei Moshe 495:2), but Rema writes (based on Smag, Yere’im, and Roke’aḥ) that one may prepare it on Yom Tov with a shinui.
The Sages did not forbid cooking on Yom Tov for the nighttime meal, even though the cooking could have been done right before Yom Tov without affecting the taste, because the general principle is that any food that will get a little worse over the course of the day may be cooked on Yom Tov. It is still permitted to cook such food nowadays, even though we have refrigerators, because without these appliances the food would get worse in the course of a day (SSK, introduction ch. 3, n. 26).
In practice, almost every food is better when it is prepared on the day it will be served; only if there is no difference must one prepare it before Yom Tov.