That is odd. Maybe when you swap to fat-burning mode?
Is it something you can condition to? I know many fellow Jewish folks get a headache when fasting on Yom Kippur.
Fat-burning mode might have something to do with it. I've been able to avoid them for the most part for quite a few years by managing my nutrition fairly closely.
It's a bit of a witches brew of enough electrolytes (especially potassium), enough protein and limited sugar. I watch electrolytes closely when working hard and sometimes let them slip with lighter efforts, especially in cooler weather.
I've never considered trying to condition to it. I focused on avoidance. Or early detection. When I notice it early on and act quickly I can contain the duration by about 75% and intensity quite significantly. Now that I think of it, maybe that counts as conditioning.