One explanation is that their strident championing is an attempt to snuff out desires they consider unacceptable ("I have homosexual urges that I hate, and so, to prevent myself from acting on them, I will campaign against gay rights"). Sometimes this defense—called reaction formation—works well; but in other cases, the urges are too strong to contain. Another possible coping mechanism is called splitting: When forbidden impulses threaten to become overpowering, the person can mentally compartmentalize them into a little box, hiding them in the unconscious. This allows him to be the really good guy the world sees while indulging his bad self in private. Intellectually, he knows he's behaving in contradictory ways, but he fools himself into denying his amoral side. Also, some seeming hypocrites act out their longings because deep down they want to be caught and punished. While all these reasons are worth understanding, none of them excuse illegal or immoral actions.
It's particularly unsettling when a supposed pillar of the community preaches one thing while practicing the opposite, but the phenomenon is hardly limited to the famous and powerful. Many people have unwanted impulses, and the more forcefully they suppress them, the more likely the urges will fester and gain control. Any desire that involves harming oneself or others (acting on an attraction to children, for example), or that is unbearably distressing, should be brought to the attention of a mental health professional. If the longing wouldn't hurt anyone, accepting it as something to think about and feel, but not to act on, will often extinguish its power and allow it to become part of a normal fantasy life.