Scientists don't fully understand why dogs rub themselves on smelly things, but there are three theories that prevail. One popular theory is that dogs dislike the smell of dog shampoos and other dog-grooming products, and they roll in stinky things to lessen the smell.
Another theory holds that dogs have a natural instinct to mask their scent with smelly odors to help them be able to sneak up on prey. This is sometimes observed in nature when wolves roll in the carcasses of dead animals to cover their own scents. A final theory is that dogs roll in smelly things in order to tell a story of their adventures to other dogs.