TL;DR: Make an appointment to see your doctor to discuss it.
Most people are shocked when a child starts banging their heads. They are afraid the child might might hurt themself, or even have autism. In reality, head banging is relatively common (up to 20% of children have been headbangers at some point), is more common in males, often starts about nine month and can last for a few years, usually doesn't involve real pain (they don't cry because they bang their heads) and is thought to be a self-soothing movement when tired or frustrated.
There is very little recent literature on head banging, so it is something you should talk to your doctor about. Until the appointment, though, these are things you can look (which of these does your child do?) for to make the discussion more informative.
From the University of Michigan Department of Psychiatry, U-M Pediatrics:
Head banging is when a child repeatedly hits their head against a solid object such as a crib, as much as 80 times a minute. This can be distressing to the parents or caregivers for concern of injury. However, the child does not appear to be in pain, but rather is calm and content. The habit usually begins around age nine months and resolves by around age two years. The episodes usually last from 15 minutes to a few hours, and typically occur while listening to music or falling asleep.
Head banging (and head rolling and body rocking) are common childhood self-comforting habits; the child typically outgrows them. In general, you should ignore bad habits (calling attention to the habit and punishment do not usually work and may even increase it), but praise, positive rewards, and patience are likely to help. (Catch your child being good and praise that.)
Teaching your child about frustration abd feeling words (so he can express his frustration and work on it with you) etc, as well as diversionary tactics, may help. Self-injurious behaviors (SIB) are often harmless, but can be worrisome if your child also has developmental delays. Talk about the habit with your pediatrician, who can help you decide whether there is any cause for concern.
From another site (Dr. Greene is the founder of DrGreene.com), a practicing pediatrician:
For some children, head banging is a way to release tension and prepare for sleep. Some kids head-bang for relief from teething, an ear infection, or out of frustration or anger, as in a temper tantrum. Head banging is an effective attention-seeking maneuver. The more reaction children get from parents or other adults, the more likely they are to continue this habit.
Pretend not to notice. And if it is part of a tantrum, do not give her whatever she threw the tantrum to get. When you notice her head banging, you might be able to get her to stop for the moment by distracting her or engaging her in a different activity. By decreasing the amount of time she spends in this habitual activity, she will outgrow it more quickly.
From the Mayo Clinic: It is important to know normal milestones. At 12 months,
Improved motor skills: babies sit without help, pull themselves to a standing position, usee various forward movements creeping, crawling and cruising) to move around; might take his or her first steps without support.
Better hand-eye coordination: feed themselves finger foods, grasp items between the thumb and forefinger, banging blocks together, stacking objects, nesting them inside one another.
New cognitive skills: find hidden objects; imitating you by brushing his or her hair, pushing buttons on the remote control, or "talking" on the phone. Your baby might be able to look at the correct object, such as a toy, when you mention it.
Evolving language: respond to simple verbal requests, understand words for familiar people and events, skilled at shaking his or her head no, pointing at something out of reach, or waving bye-bye, babbling takes on new inflection and evolve to words such as "dada" and "mama." You might hear certain exclamations, such as "uh-oh!"
Delays in these skills, or regression of skills accompanying head banging may be a sign of autism. In this case, you usually see:
delayed speech, lack of normal interest in others or in childhood activities, or a regression of early speech and sociability. Communication difficulties are the most serious problem. Patients with verbal auditory agnosia (“word deafness”) understand little or no language (see accompanying table on communication deficits in autism). In addition, children with autism do not play normally. While they may appear to have long attention spans when engaged in solitary activities, they cannot focus on activities performed jointly with others. Parents may describe them as independent rather than aloof and may even be proud of their self-sufficiency. Children with autism have frequent temper tantrums, require less sleep and awaken frequently during the night.
From Dayton's Children's Hospital:
Head banging can be upsetting for parents to see. But in most cases, occasional head banging is a form of self-stimulation, self-comfort, or a release for frustration and does not signal another problem. As a parent, you can help by addressing any underlying causes of emotional upset and protecting your son from injury as much as possible. Try not to make a big deal about the head banging or scold him for this behavior. While head banging is common and usually nothing to worry about, in some kids it can be part of a developmental problem. Frequent head banging, particularly if there's a question of developmental delay or abnormal social interactions, should be evaluated by a doctor.
The reported mean age of self-injurious behavior (SIB) onset was 17 months, and head banging was the most prevalent topography. Functional analyses identified sources of reinforcement for SIB in 62.1% of cases; with the inclusion of all forms of problem behavior, sources of reinforcement were identified for 87.5% of cases. Function-based treatments were developed for 24 cases, with functional communication training prescribed most often (70.8% of cases). Implications of these findings for the development of early intervention programs for SIB are discussed.
Bad Habits/Annoying Behavior
Head Banging: A-to-Z Guide from Diagnosis to Treatment to Prevention
Characteristics and Symptoms in Patients with Autism
Is Head Banging Normal?
FUNCTIONAL ANALYSIS AND TREATMENT OF SELF-INJURIOUS BEHAVIOR IN YOUNG CHILDREN: A SUMMARY OF 30 CASES