Dehydration
Alcohol is a diuretic, which makes you wee more. In fact, you lose far more water in your urine than you are taking in the drink itself. Dehydration causes the brain to shrink away from the skull slightly. This triggers pain sensors on the outside surface of your brain.
Attack of the free radicals
Free radicals are harmful molecules formed in the liver as it struggles to break down ethanol. Usually, these are seen off by an anti-oxidant called glutathione but its reserves can run low after a drinking session.
The foolproof hangover cure
No, sorry there isn't one. The general advice is to drink plenty of water, possibly even a sports drink to rebalance those electrolytes and go back to bed.