It could be a number of things from wider bars to not being relaxed while you’re riding. For example, I’ve got C5/C6 vertebra problems in my neck that put pressure on nerves and cause neck and arm pain. It’s particularly bad when I’ve been standing on the pedals through technical stuff a lot, as my head’s tilted back more as I look ahead and I’m tense because I’m a wuss. It used to be a problem until I learned to swim properly and started open water swimming, which developed the muscles around the neck.
The important thing is, everybody’s different and bad advice on neck pain can cause even more problems. So I’d go to a good physio and get checked out, rather than ask on a forum and get a thousand answers.