Why does glass shatter when heat is applied to it?
This is not a chemical process.

Objects typically expand when heated. Think in railway profiles in the summer, think in loosening a stuck nut by heating it with a blowtorch.

However, when the material is under stress and a bad heat conductor, unevenly heating will result in cracking.

While it is a pity for the cup, the breaking of glassware to thousands of rounded (!) pieces upon uneven or punctual (mechanical) impact may be exactly what you want under different circumstances. Think in tempered (toughed) glass used in windows of railroad passenger cars.

On a side note, there's the Bologna Bottle. In the making, these bottles are slowly cooled on the outside - but very rapidly on the inside, which maximizes the stress.

As a consequence, you might use the bottle as a hammer to drive a nail into something, but beware if you drop something in the bottle. Here's a video to demonstrate the effect. (Be warned that there's a lot of screaming kids in it.)