Gum disease, like gum recession, is a common cause of dentin hypersensitivity because the roots of the teeth become exposed as bacteria eat at the ligaments that hold the tooth in place. The roots of the teeth are not made of enamel and many of the underlying tubules become exposed once the ligaments are lost. However, as noted earlier, not every tooth with gum disease will have pain to sweets; instead, it will only happen to teeth at risk for dentin hypersensitivity.
It should also be noted that some bacteria in gum disease can also convert sugars, sweets, and candy to acids increasing the intensity and likelihood of sensitivity.
Teeth with gum disease will need a deep cleaning and may need a filling to eliminate the pain. It may be beneficial to also try anti-sensitivity toothpaste for a few weeks for sensitivity relief.
Thus we see, dentin hypersensitivity caused by cavities, fillings, tooth wear, gum recession, gum disease, and fractures all cause your teeth to hurt to sweets and sugars.