I believe it is because the glass has a smaller coefficient of linear expansion than the water. The glass undergoes thermal expansion and thus when it heats up, it expands and when it cools down it contracts. The inside and the outside of the glass does not reach an equilibrium temperature very quickly since the glass has a low thermal conductivity. The surface of the glass rapidly contracts while the inner surface is expanding which causes the glass to crack.