Light-colored skin (nobody but an albino is "white") did not occur suddenly. There is a continuum of skin shades from brown in Africa and southern India, through Mediterranean olive-shade, to Scandinavian lightness.
As humans expanded in a northerly direction, those who were more optimally adapted to their current climate had better health and were more likely to survive, bear children, and care for them into adulthood.
Light is one thing but white, which orginated at mid-lattidues, is another. Skin color does not have a linear relationship to environmental UV strength in modern humans. White is a cosmetic preference. Some women put white powder cosmetics on their face. You can witness the cosmetic selection process happening now in American black communities, where lighter skin is often a preference, although now it is driven primarily by mate selection than mother cultivation.