The Overcoming Bias site has posted an interesting article on Self Righteousness. They make several interesting points:
"People with exceptionally strong convictions about their moral goodness are likely to follow extreme courses of action because they can convince themselves that whatever they do is good. When the right course of action is ambiguous ... such people are likely to gravitate to opposite ends of a range of behaviors. When there is wide social consensus that something is wrong, they tend to conform to social norms."
I think this largely depends on whether they draw their sense of morality from external or internal values. If we look at this behavior in terms of Kohlberg's Stages of Development, the Self Righteous are usually working at the Preconventiality Stage of Morality. Their values are determined by external, society forces and they adhere to them out of fear of punishment. Given this viewpoint, it is extremely important to find what is "right" and punish what is "wrong". This simplistic way of viewing morality leads to the very black and white thinking seen in the self righteous and the very high and certain assessment of their own morality.
As we move up the levels of Kohlberg's Stages of Morality things become less certain, less clear. The individual becomes aware that more than one viewpoint can be "right" and that individual morals can conflict with societal norms and still be "right". What is "right" becomes more murky and how moral one is becomes less certain. And when one is looking for the "right" out of a need to find what is most just or what best benefits the community, when one has to consider all possible sides of an argument and its implications rather than simply consider the punishment "extreme courses of action" and black and white thinking are less likely to occur.
I think there is another element at work as well. In my experience, people who tend to be very self righteous are extremely hypercritical (of themselves and everyone else) and tend to exert their self righteousness on others hoping they will come off looking better than the "wrongdoer" by comparison. It can also be used as a form of distraction. If they can direct everyone's attention to the "wrong" someone else is doing perhaps everyone will not see how flawed they are. Of course, this is all functioning on the subconscious level.
An interesting article and interesting topic.