While dogs are well domesticated, they do retain certain instinctive actions passed down through their ancestors. In some cases it’s the survival instinct and in others, just because it feels good.
Dogs disguise their own scent by rolling in smelly things. This ancient instinct confuses their prey when they are hunting or helps to keep an enemy at bay. If this upsets you, please don’t use punishment – it’s cruel and it doesn’t work for any unwanted behavior.
Some dogs roll in stuff to get rid of an odor such as meeting a skunk and being sprayed. If you’ve just bathed your dog, the smell of the shampoo may be annoying to him/her and your dog will roll to eliminate the scent.
Dogs roll on objects for other reasons too. It could be to relieve an itch that the dog can’t reach otherwise. Or it could be an expression of joy. Submission is another reason dogs will lie on their backs.
If your dog rolls in something objectionable, try distracting him/her with a toy or a loud noise. Giving treats may encourage the behavior as the dog may think s/he has done something wonderful.
You can discourage this behavior by keeping your yard/garden clean and free of any stinky stuff. Also, try using a non-scented natural shampoo to wash your dog.
Please remember, while we humans think rolling around in that awful smelling stuff is disgusting, it is very pleasurable to our dogs.