No one knows what causes OCD. We do know that certain nerve pathways in the brain are overactive in OCD, and that when these pathways are "calmed," either with cognitive behavior therapy (CBT), medication, or psychosurgery, symptoms are reduced. In some cases, called PANDAS (Pediatric Autoimmune Neuropsychiatric Disorders Associated with Streptococcus), we believe that the antibodies created by the body to fight a streptococcus infection (e.g., a strep throat) can actually attack part of the brain, resulting in OCD, often literally overnight.
We also believe there is a genetic component to OCD, that is, it tends to run in families. Interestingly, however, family members may have completely different types of OCD. For example, a parent may have contamination or hoarding symptoms, and their child could have symmetry or harm obsessions. This observation supports the idea of a genetic link rather than symptoms being taught or modeled.
Two old notions about the cause of OCD have been thoroughly laid to rest. The first is that OCD symptoms can result from faulty parenting (such as overly strict toilet training). The second is that OCD symptoms represent unconscious conflicts, guilt feelings, or a need for control. There is simply no evidence for either of these ideas, but countless patients and their parents over the years have been misled into thinking that their OCD is somehow their fault. One especially cruel example of this is when new mothers have been told, authoritatively but erroneously, that their fears of harming their baby are a result of unconscious anger or other negative feelings toward their child.