Over the last few decades it has been established that OCD is a neuropsychiatric illness. Establishing that OCD has a physical cause inside the brain was an important step in getting the illness taken seriously by all members of the medical profession. The brain is a complicated organ and the understanding of OCD as a neuropsychiatric illness is still in its infancy. However many studies are providing scientists with hints about how the brain is malfunctioning in patients with OCD.
I am no expert on neuroscience, but let's look at some of the likely conclusions that have been made by scientists.
Brain imaging studies of patients suffering from OCD show over-activity in certain parts of the brain compared to non-OCD sufferers. These parts include the the orbital cortex, and the caudate nucleus. The orbital cortex is towards the front of the brain and the caudate nucleus is part of a primitive core of the brain called the striatum or (basal ganglia).
The orbital cortex becomes active when the brain detects an error - ie something that is deemed wrong that requires some kind of action. This is found, e.g., in animal experiments where electrodes are implanted in the brains of living monkeys who are then exposed to experiences that don't fit the monkeys' expectations. Use of the orbital cortex generally requires effort.
The caudate nucleus is thought to be responsible for filtering thoughts that are important from thoughts that are not. The caudate nucleus works without conscious effort.
Another part of the brain thought to be responsible for the emotional aspect of OCD is the cingulate gyrus. This lies in the deep part of the cortex and is thought to cause the unpleasant feeling that something urgent needs to be done in response to the OCD thought. The cingulate gyrus is connected to the orbital cortex and the caudate nucleus and affects your gut and heart.
Using the above fundings, a compelling model for how OCD works has emerged over the last few decades. In this model the caudate nucleus is considered faulty and so is using more energy than it should be. It allows erroneous thoughts through that healthy people would not be alarmed by (let's call these "OCD thoughts"). These OCD thoughts are picked up by the orbital cortex which tries to process and eliminate them. This prompts the sufferer to perform urgently some compulsion. It is as though the orbital cortex is trying be a substitute for the job of the faulty caudate nucleus. Not only does the overactive orbital cortex drain the sufferer of energy because it is trying to do a job that it was not designed to do, it also does not allow the the caudate nucleus to repair itself. As Brain Lock (by Dr. J.M. Schwartz) puts it, "The end result of a caudate nucleus problem can be that the error-detection system gets stuck in the ON position, leading to a something-is-wrong feeling that will not go away."
Behaviour therapy and drug treatments for OCD have, however, each been shown to help repair the caudate nucleus. These therapies (separately and together) lead to a reduction in activity of the caudate nucleus, meaning that it starts to do its proper job of filtering thoughts automatically. This in turn leads to a reduction in activity in the orbital cortex. This is evidence that the therapy is helping to 'rewire' the brain.
I have also read about other parts of the brain that are thought to play an essential role in OCD (e.g. the amygdala and the hippocampus), but I have yet to see how they integrate into the above model.
There is other evidence too.
Clinical trials show that patients with OCD often respond well to medications that increase the amount of available serotonin in the brain. Serotonin is a neurotransmitter thought to be an important factor in happiness. Such medications include the popular SSRI (Selective Serotonin Reuptake Inhibitor) family of drugs. The performance of the orbital cortex, the caudate nucleus and the cingulate gyrus mentioned above are affected by serotonin.