Darker skin is found in indigenous populations nearer to the equator. Lighter skin is found in indigenous populations further from the equator (see map above). There is more UV radiation near the equator (see map below). The sun’s UV rays can destroy folate levels. Folate is needed for DNA synthesis. Low folate levels contribute to birth defects such as spina bifida. UV from the sun is needed for the body to create vitamin D. Skin has to be dark enough to protect folate levels while light enough to create vitamin D.
Jablonski, N. G., Chaplin, G., N.G.J., & G.C. (2003). Skin Deep. Scientific American Special Edition, 13(2), 72-79.