This is a hold-over instinct from before dogs were domesticated. They would roll around in a heavily scented object to mask their own scent, when hunting. For more information see:
Why Dogs Love to Roll in Smelly Stuff - Succeed by Understanding Behavior: School for Champions