Most children who rock or head bang started between six and twelve months of age. It often consists of rocking on the hands and knees and potentially banging the head against the side of the crib. Some children do this to soothe themselves and some children do this, particularly at bed time, as part of a ritual that helps them fall asleep.
Most children do stop this activity spontaneously between three and four years of age, however there are some children who continue to do it through five or six. If it persists longer than this, it would be reasonable to evaluate it further and find out if there are any other psychological stresses that may be contributing to the symptoms. I would recommend that you see if you can encourage him to develop another bed routine. If you continue to have difficulty with it, I would recommend talking to your pediatrician.