I learn this tactic to discipline baby from the book "Raising a happy, unspoiled child".
When he bangs his head to the wall or does something to hurt himself, you have to stop him immediately. Take him to another room, let him sit and you hold his shoudler firmly with your hands, don't let him move. You remain silent, after a few minutes, you tell him if he does that again, you will do the same thing to him. This is a good way to discipline baby.
2 possibilities:
1. he feel unhappy or angry, he don't know how to express, so he hurt himself
2. he want to test your response , and see how nervious u are.
So, u must stop him and tell him "no", try to find out why he do this and let him know u care about him, but u will punish him if he hurt himself again .