It can also be the wrong pillow. Sounds daft I know, but your pillow should match the way you sleep. So fx. if you sleep laying on the side it is best to have a pillow that is somewhat firm and tall to support you head and neck not making it tilt too much, however this is more about avoiding issues than solving them.
Unless the waking up and pain thing goes away in a few days definitely go see a doctor.