https://www.pedigree.com/dog-care/dog-facts/why-do-dogs-roll-in-smelly-things
Why Do Dogs Roll In Smelly Things?
As you’ve undoubtedly noticed, you and your dog have very different notions of what smells nice. To your dog, something could smell quite wonderful. But to you, in a word, it’s yucky. And vice versa.
A few theories
Here’s a perfect example of something that smells nice to you but not to your dog: the perfumes used in dog shampoo. You may find them pleasant, but many dogs dislike their odor. As a result, as soon as your just-bathed dog gets the chance, he finds something that smells more acceptable to him—garbage, dog feces, animal carcasses—and starts rolling around in it.
Have you ever caught your dog rolling around in poop? Believe it or not, this behavior is quite common—and very natural. Many believe it's instinctual behavior, harkening back to the days when your dog’s wild ancestors would mask their scent to help them sneak up on their prey. Wolves, for example, have been observed rolling in animal carcasses or the droppings of plant-eating animals, to cover up their own smell during the hunt.
Here’s a related theory that also conjures up the pre-domesticated past of canines: wild dogs may have rolled around in smelly things to “tell” their pack mates where they’ve been and what they’ve encountered in their adventures. It’s his way of saying, “Hey, smell where I’ve been!”