As you said, it may be because of wrong posture while sleeping and that is common. Swelling maybe because of muscle spasm. This persists for short duration.
Next Steps
Consult an orthopedist to rule out other possible causes. Hot fomentation, volini spray or gel for local application and muscle relaxants will benefit you.
Health Tips
Use thin pillows while sleeping