The traps connect into the neck ofc, When I train my neck with a neck harness I sometimes feel trap soreness the next day from doing the extension movement.
When you shrug, do you only move your shoulders, or do you have a tendancy to move your neck downwards aswell?
I see many people (including myself) do this as it makes them think theres more ROM, which ofc in a shrug, theres hardly any, this is also why you see people bending their elbows and curling the weight slightly.
Becuase the rom isn't as much, people are trying to mentally and pointlessly compensate.

So if your bringing your neck down abit to meet the traps, don't. That COULD be the reason you get headaches from shrugging.
It could also be weak neck muscles, I'd recommend looking into the subject a little more.
There are countless studies of women who have chronic neck pain and headaches, all of which took part in resistance training studies (where they trained traps, delts and neck, I think mostly with rows, upright and machines etcetc, with some direct neck work) and most if not all saw improvements in a matter of weeks. I did some research on this topic a while back, and there are many studies to support this, however all involved women, dunno if I found a single study involving men and neck pain.
The soreness you feel in your neck is much more likely to be soreness in your levator scapulae than really your upper traps. In the extension work you do with your neck I would be willing to bet this is the case again. Neck pain in the studies you're talking about I would be willing to bet is due at least in part or with a large majority to weakness in the deep cervical neck flexors. The forward head posture so common these days is likely to cause both neck pain and perhaps headaches.
Think of this, your head weighs 8-12 pounds. When you put your head forward you're creating a longer and longer lever arm for your muscles to support 8-12 pounds. Which isn't all that light. Further you're making the path for air into your body more difficult to traverse, etc.
Then consider that when you do a normal shrug you're engaging a host of muscles that are downward rotators of your scapula and not necessarily maximally engaging your upper traps. For shoulder health and function, probably hardly ideal. For upper trap training, probably hardly ideal. For mass? Great.
Also everyone is talking about traps so generally. There's three sections, upper, middle, lower, endless functions and each has unique qualities and insertions, lines of pull, etc. Pretty sure the OP was only referring to the upper section and a replacement for the exercise of shrugs.