Almost any medicine might be able to cause a headache. We diagnose this if there’s no other cause for a patient’s headache, and they had recently begun taking something new. Then we’d look it up in our resources for medication side effects, and see if the medication had ever been reported to be associated with a headache (but we’re careful with our conclusions; please see Beware Reading About Medication Side Effects).
The same goes for herbs, supplements, and street drugs. In terms of the latter, not only might the drug cause headache, but withdrawing from it might also. Same holds true for medicines & any substance.
If a person gets a headache repeatedly in a certain environment, we’d suspect an environmental cause. These can range from life-threatening (like carbon monoxide), to simply annoying (like ammonia). Diagnosis takes detective work.