Pain in jaw can be due to stress or due to bad sleeping position. Pain in teeth/tooth can be due to infection .
But as you wrote that it happens occasionally then the reason behind pain could be stress , bad brushing techniques or due to any ear infection.
Avoid sleeping only from one side , try to switch sides simultaneously. Avoid eating hard food. Don’t put unnecessary pressure on your teeth . Do some meditation and try to relax .
Next Steps
Consult your nearest Dentist