I had the same experience years ago with a certain wine I was drinking. My brother-in-law, who makes his own, explained what the problem was. It is due to a too high a level of sulfides or something like that in the wine. That is an indication of a bad brew.....
That's why I think there probably is a chemical cause for many headaches --- I almost never get headaches but when I had that kind from the wine --- it was about as bad as I could imagine. I'd rather avoid the cause than try to cover up that kind of pain.