Repellents generally work by taking advantage of an animal's natural aversion to something, and often the thing chosen is something that the animal has learned to avoid (or instinctively avoids) in its natural environment.
Chemical repellents mimic natural substances that repel or deter animals, or they are designed to be so irritating to a specific animal.