It’s difficult to say, with only one trial, that the iron pills are what cured your headache.
First of all, iron levels change depending on diet, so it’s possible that the blood test you had did not reflect the levels of iron in your blood when you have a headache.
It’s also possible that, despite feeling better after the pill, your run of tiredness was not simply caused by poor iron. Anything from an old matress to thyroid problems can cause tiredness, and poor iron may have simply compounded the issue.
Thirdly, it’s possible that your headaches were not all caused by the same problem, poor iron or no. I’ve had headaches from dehydration, poor lighting, sinus problems, and a host of other things I’ve never been able to dissect properly. All were really painful (to the point of vomiting) and none responded properly to medication once they got going.
Best advice: see your General Practitioner like Desmostylus suggests and work out a proper diagnostics system.
Best Wishes.