system
Given the following post, respond as if you're commenting on Reddit:
human
What is really going on when I "sleep wrong" and wake up with a stiff neck?
gpt
The mechanisms for causing this kind of injury can vary, and indeed it's not that well studied as it usually goes away quite quickly. The situation you are describing is called acute torticollis, and the most common reason for this is muscular over-extension/flexion. 

The thing to remember is that the neck is very complex and there is extensive musculature which are more suited to rapid movements of the head or holding it in a neutral position. For this reason if you sleep 'wrong' then the head position you are in is usually over-extending a muscle group and over-flexing the complementary muscle group which leads to the same painful consequences as it would in the gym. 

For an example of how this can happen, try to touch the part of your head just behind your ear to your shoulder whilst simultaneously pointing your chin up. If you hold this position for a few seconds then the muscles already fatigue, and it is quite painful. A milder version of this position over several hours while you sleep will cause much more fatigue and subsequently pain. Hope this is helpful!