Typically, it's for status and for companies to sell more items. It's an easy form of monetization that can go beyond just the in-game pet itself but also really popular pets can even be marketed as collectiable real world items: such as figurines, key chains, and plushies. Remember, it's entirely in the name, VANITY Pets. they apeal to our vanity to say we have something someone else doesn't.
I agree, ti shouldn't work nearly as well as it does, but people are vain, especially gamers, we're practically peacocks without feathers, so we compensate with shiny armors and limited edition skins or mounts, and vanity pets all in the name of having the largest tail, with the most numerous and beautiful feathers. Gaming companies would be absolute fools not to take advantage of our vanity as part of a monetization scheme. If it wasn't pets, it would vehicles skins, weapon skins, armor skins, flashy new ability animations and effects, unique mounts, and of course all those cosmetics we love. Pets are just one more series of feathers we can all scramble to add to our tails to show off with.