You might have strained your back muscles due to sudden stretching. The muscles are relaxed when we sleep so we should be careful before suddenly stretching them. Do proper warm up movements before stretching.
For your current problem, meet a qualified physiotherapist as they can help you with reduction in your pain and for longer run get some isometric exercises of neck.
Next Steps
take physiotherapy treatment to reduce any inflammation or manual therapy for locking of your facet joints.
Health Tips
take proper rest, use hard/ orthopaedic beds. avoid sleeping in soft bed, pillow should not be very high. use folded bedsheet to sleep if convenient.