While a majority of dogs have black noses, not all do.
The noses of dogs such as vizslas and weimaraners match their coat colors, red and silver, respectively, and it is not unusual for puppies of any breed to start out with pink noses that then darken as the animal matures.
Some Shetland sheepdogs retain pink on the insides of their nostrils for their entire lives.
Dogs have most likely developed black noses as a protection against sunburn.
While the rest of the dog’s body is protected by fur, light-colored noses are exposed to the full force of the sun’s rays.
Pink-nosed dogs, hairless breeds and dogs with very thin hair on their ears need to be protected with sunscreen when they go out of doors, just as humans sometimes do, or they risk the same sorts of cancers and burns.
In addition, dog breeders have long singled out a black nose as the only acceptable color for many breeds.
Though this is based on nothing more than an aesthetic preference, it still serves as a selective influence for people breeding pedigree dogs. This adds a bit of human-directed evolution to what was already a natural tendency towards black noses.
Black nose leather contains the skin pigment melanin, specifically in its dark brown or black eumelanin forms. Melanocytes, the cells that produce the raw material, secrete it into the skin cells, and the sun then darkens it further.
Melanin in skin cells protects the DNA in cells from mutations caused by ultraviolet radiation from the sun.