Thanks for your question.
Can I ask you does this happen when you have very hectic and stressful schedule? Have you noticed that pattern? On top of if your working out loads maybe?
Also it can happen if sleeping in hotel rooms when travelling if air conditioning is on at night, or an open window when it’s cold?
When you say pain, was the pain just tight sore pain? Or was it sharp pain? If sharp pain I would see an Osteopath first incase it’s something else, like a facet joint that clamps onto the nerves? Or if it’s tight muscle then a sports massage would be great.
Here’s some stretches for your neck for you to do in the meantime, hopefully they help.
https://youtu.be/ABV47WMe4lc - Scalenes stretches
Levator scapulae stretches - https://youtu.be/F8oDQEwbAuI
How to fix a stiff neck - https://youtu.be/AD6YTTb5WQY