People who stuck around sun-baked areas near the Equator developed more melanin in their skin, which protects them from excessive ultraviolet radiation as well as excessive Vitamin D absorption (too much is too much, after all). And the result was that the increased melanin levels cause a darker skin tone, because melanin carries with it a brown pigment. And of course, the darker the skin, the more melanin there is in the tissue.
Whereas people who decided the Equator was too wack (Europeans and Asians, mainly) moved further north where the sun was less harsh, and their bodies produced less melanin. The results are the opposite: Less sunlight to worry about up north so a lower amount of melanin still protects them from UV rays and allows the right amount of Vitamin D absorption to happen, but less brown pigmentation in the skin creates that yellow-ish or peach-colored complexion Europeans and Asians hold so dear.
So if someone has darker skin, their ancestors were badasses who toughed it out in the blistering sun, and if someone has lighter skin, their ancestors ran for the sweet, sweet hills and never looked back.