When the skin is exposed to sun for long periods of time, it releases skin pigment (coloring) called melanin, which temporarily gives the skin a darkened appearance.
Because people inherit genes from their parents and the skin color itself from a thing called Melanin i believe and the higher level's on Melanin the darker the skin