Pigmentation occurs when the skin produces excess melanin, the natural pigment responsible for skin color.