Hi local parent educator here,
There are two reasons something like this maybe happening. The shaking of the head can indeed be a new trick. The only thing that makes me think it is not a new trick is the fact that he is doing this in his sleep. When children learn a new trick they will rehearse what they have learned during the day each night before going to bed, they will not typically do the same activity in their sleep. Some do, most do not.
The other scenario is that he may be telling you that his ears are bothering him or his neck is out of whack. Has he fallen or bumped his head recently?
So you don't have to worry about this, and can see it clearly for what ever it is, I would suggest a trip to the Dr. And if your pediatrician says it isn't his ears and not to worry about it, but yet you still feel in your guts that something is amiss then I would HIGHLY recommend seeing an osteopath. The best resource I have in Tucson is Teresa Cisler.
If you can't find her number then email me at: ____@____.com