Often I will have people ask me about a pet's dewclaws or extra toes. Why does this happen? Where do they come from? Do we need to take them off?
Bone development, including toes, is determined genetically. Genes within a breed and individual will cause cells to develop a certain way and guide how many limbs an animal has, how long and thick the bones develop, where the limbs are placed, and so on. Pretty much everything to do with an animal's physical appearance and function is governed by genes. We haven't reached the point where it is easy to manipulate genes and significantly affect how physical development takes place. But we have been able to achieve a similar result by carefully breeding individuals that look the way we want them to. Over generations we can cause the face to be shorter, the leg bones to develop curved, and toes not to develop at all. Once those characteristics are common within a breed or bloodline they are maintained through continued selective breeding.
Some dogs are born without dewclaws. Some are born with double dewclaws. In most cases this is based on our particular idea of how a given breed should look. While hind limb dewclaws are undesireable on a Labrador retriever and have generally been bread out of them, two dewclaws per hind foot are breed standard for the Great Pyrenees. Because humans decided that the breed should look a certain way they breed to have fewer or more toes than the wild anscestors.
Sometimes this happens naturally. Even with careful breeding we can't make 100% guarantees for how genes will combine or activate. Sometimes you'll get a dog develop dewclaws even if other members of the breed don't have them. Some cats have an extra dewclaw (called polydactyly), and the tendency for this trait can be passed to offspring. These happen when specific genes are activated that would normally remain dormant, and the same thing can happen in humans.
In the large majority of pets nothing needs to be done about these extra toes. I'm not an advocate of routinely removing them and I challenge the old notion that they are more likely to be torn off. I've tracked broken or torn toenails at my own clinic and haven't seen the dewclaws any more affected than any other toe. So I typically tell clients to leave them and not worry about it unless specific problems develop.