There is also a genuine trade-off, which is worth knowing because it explains why pigmentation is not simply maximised everywhere.
Skin needs some ultraviolet exposure for vitamin D synthesis. Heavy pigmentation reduces that, which at high latitudes with weak winter sun becomes a real cost. The global pattern of skin pigmentation tracks latitude reasonably well, and the usual explanation is exactly this balance — enough protection where the sun is strong, enough transmission where it is weak.
That is a nice illustration of the general point: evolution rarely produces maximal anything. It produces compromises tuned to a particular environment, and moving the population moves them off their compromise.