There are two things happening: First melanin absorbs the energy from the UV radiation and releases it as infrared energy and thus protects the cells in the skin. This happens in all people, the deeper the skin color is, the better is the protection.
What is different between people is the amount of pigment they produce, the number of melanocytes is approximately the same. This depends on their genetic backgroud and is influenced by mutations in the pigment production pathway. As this is relatively complex, there are numerous positions which can influence the ability to tan, so I will only name a few.
The rate limiting enzyme for the pigmentation is Tyrosinase which catalyzes the first step of the melanin biosynthesis and oxidizes the amino acid tyrosine into DOPA. Without tyrosinase humans are not able to make any pigment at all which causes albinism. This is pretty drastic and doesn't happen too often. See reference 1.
Other possibilities are mutation in the signalling towards pigmentation, more specifically mutations in the MC1R gene which encodes on of the receptors. These mutations affect the ability to tan and are associated with red hair color, pale skin and freckles (most of the red-haired people carry at least one mutation in their MC1R gene). See reference 2.
Then there are mutations in the tyrosinase gene, which results in an enzyme with a lower processing rate. Because of this, less pigment can be made as the amount of materials is limited. See references 3 and 4.
The diversity of the human pigmentation is influenced by all these (and much more) genes. Have a look at references 5 and 6 for details.
- Analysis of tyrosinase mutations associated with tyrosinase-related
oculocutaneous albinism (OCA1).
- Red hair is the null phenotype of MC1R.
- Mutations at Critical N-Glycosylation Sites Reduce Tyrosinase
Activity by Altering Folding and Quality Control
- Mutational mapping of the catalytic activities of human tyrosinase.
- Molecular genetics of human pigmentation diversity
- The genetic architecture of normal variation in human pigmentation:
an evolutionary perspective and model