Hi
It might have been spasm in your Traps. As you said if this is forward head posture please get it checked at a Qualified Physiotherapist. Else this kind of pains keep bothering you.
Next Steps
please do stretching for your and correct your neck posture
Health Tips
use hot packs after your work