Although scientists don't really know why dogs like to roll on dead animals, many assume it is because they are trying to mask their own scent. Other theories suggest they do it to rid themselves of an odor they find unpleasant.
Dogs are pack animals and, as pack animals, they hunt in groups. If a dog can hide its own scent, it will have a much easier time sneaking up on prey without being recognized. All dogs in a wild dog pack will often roll around on the smelliest thing they can find before hunting.
Despite the fact that dogs have been domesticated for thousands of years, this instinct is still hardwired into their brains. Although rolling on dead animals is a disgusting habit, a dog can be trained with positive reinforcement to resist the urge.