It is the amount of melanin in their bodies that affects their skin complection. people with darker skins would have a great amount of eumelanin (a type of melanin) in their skins.

another explanation would be that
In Charles Darwin's theory, there are lots of factors that can effect a person's genes, thus mutation occurs, or simply saying, HUMAN EVOLUTION

one of these factors is Natural Selection,
All organisms have reactions to their environment, and/or, their environment has a huge effect on an organism. Naturally, Africans live closest to the equator, or the middle of the earth's surface. Meaning they have been living there with the heat and the sun's light focused on them. And by the amount of years that have passed, to adapt to their environment, their bodies may have developed dark skin, and dark skin is less likely to get sunburned and to have skin cancer.

Hope it helped! :)))
They were exposed to their biological environment which was (savannah i think)
Because of that, their skin tend to have more melanin than other people.
If you're to ask me logically, God made them for who they are and shall not be questionable.
hoped it helped