Pets wag their tails as a way to communicate their emotions and social cues to other animals and humans. It can express feelings such as happiness, excitement, or friendliness. It is a form of body language that helps them interact with their environment and other beings.