Try doing it yourself - sit there and shake your head vigorously forward and backward or do it side to side. I'm certain that as an adult it gives you a headache and might make you feel a little dizzy. Did it give you 'the spins'? But for a child, it's a brand new, super cool sensation!
Here might be their thought process: "Whoa, this feels different and cool! Whee! It makes me a little dizzy! Neato!" Followed by "Wow, I really get mommy's attention when I do it, too. If I do it some more, she'll get even more focused on it."
Trust me, I know it is frustrating and annoying. You're probably wondering if he's going to crack his skull open on the wall or the hair chair. As long as you don't think he is in danger of hurting himself, let him bang and shake all he wants. Try to ignore it if possible. If the behavior does not draw attention, then it might become extinct.
We've had to use 'ignore' for a lot of things. Our baby used to do the head shake/bang in the high chair too. We ignore it and it is no longer a 'cool thing' for him to do. He used to throw toys and slap the tv...after about a dozen times of saying "no" (which always resulting him in running RIGHT back to the tv and doing it again), we just started ignoring it. I'd follow that up by turning to my husband and starting up a fake "really interesting" conversation. The baby didn't get the attention from the unwanted behavior, so it ceased. Now at 20 months he's starting to throw tantrums. He starts screaming, crying, and throwing himself into a dramatic puddle of mush on the floor. Guess what we do? Clear the area and make sure in his 'flailing and wailing' he can't hurt himself', step over him, and sit down and go about our business. We don't draw attention to the tantrum and it stops quickly.
Good luck! Welcome to the world of the frustrating and scary things our children will do. Wait til it is climbing on and jumping off the furniture...