My headgasket went first. But I believe mine was related to pre-ignition which will push out a headgasket unlike detonation. In detonation, the entire mixture is ignited too early and the majority of it burns releasing the energy contents too early. This pressure wave of energy expansion is absorbed by all components in the combustion chamber and the piston is usually the weakest link. Considering the rise in temperature as the charge compresses, you can see how it burns quickly near TDC.
In pre-ignition, the expansion of energy from fuel combustion related to cylinder heat occurs right when the piston is nearing TDC. So basically, you get a ****-ton of pressure, just like boost, right before the piston hits TDC. Then the piston compresses that, and you can see how that would push the gasket out.
You can see a picture of the inside of the combustion chamber during normal and detonation scenarios here:
http://not2fast.com/engine/
Detonation can be a direct result of pre-ignition. Mostly, detonation is when you are getting nearly full energy release from the charge and pre-ignition is when the charge is beginning to burn too early resulting in high cylinder pressures. If you picture it in your head correctly, you will see how the pre-ignition causes a ping sound and detonation causes a knock sound. Note, not all detonation and pre-ignition is audible..