A portion of migraine may be caused by blood vessel “swelling”. Coffee has the effect of constricting blood vessels, that's why.
In our body there's a substance called adenosine, when adenosine and adenosine receptors are combined, they dilate the blood vessel. When caffeine enters the body, it will replace adenosine to bind with adenosine receptors, then inhibite the expansion of blood vessels. Then the feeling of headache is releived.
In fact, caffeine is used in quite a few drugs used for treating headache.