When you have cavities in your teeth taking any sweetend drinks or food causes sensitivity or pain. What could be the reason?
The outer shell of a tooth is enamel, which is hard and dense so that not much can penetrate it. Under that is dentin (or dentine), which is bony but has microscopic channels running through it to the center of the tooth where the pulp and nerve reside. If the enamel is breached, as with a cavity, crack, or wear, the dentin is exposed to the environment of the mouth. When sugar comes against the dentin, it draws fluid out of the microscopic channels (because sugar attracts water strongly). The fluid flow causes pressure changes around the nerve of the tooth, which reports the change to the brain where it registers as pain. Dentin is highly sensitive not just to sugar, but also to hot, cold, pressure, and other stimuli. (This sugar response is a short term one; the influence of sugar on bacteria is a longer-term effect in which the acid generated by the bacteria eats away the enamel layer.)
This is a bit of a basic answer.
According to the website article "Dental cavities" (Medline Plus), the bacteria normally in your mouth converts many foods, particularly starch and sugar into acid that forms a part of plaque. These in turn cause dental caries or decay, according to this Wikipedia article:
Dental caries, also known as tooth decay or a cavity, is an infection, bacterial in origin, that causes demineralization and destruction of the hard tissues (enamel, dentin and cementum), usually by production of acid by bacterial fermentation of the food debris accumulated on the tooth surface
A possible reason you would feel pain from a cavity in contact with sweet foods and drinks, or anything really, is due to the cavity being large enough that nerves are exposed.