I get them a lot too, especially in the heat. Not sure I really know what causes them but for me it seems to help if I drink quite a lot after running, particularly a rehydration solution. I make my own from the WHO recipe - 1 litre water, 8 teaspoons sugar, 1 teaspoon salt. I tend to drink a couple of glasses of this as soon as I get back in. I think it helps.
Also found that ibuprofen works much, much better than any other painkiller for these headaches, although I try to avoid it unless it's really bad.