I remember a scene in Fried Green Tomatoes (shut up, it's a good movie). Basically, a woman is on trial for killing a man who was a soulless heartless evil person and deserved it, and it was in self-defense (um, this was awhile ago, and I might not be remembering it right: just go with me). However, she's going to be convicted of murder, since this is awhile ago, back when women didn't get off for self-defense unless they were rich.
The town preacher comes in as a surprise witness. He uses his own book to swear on and says, "She was helping me with a church-related function that night, so she couldn't have killed him."
The woman stares in shock as all charges are dismissed. She says to her friend, "I can't believe he just lied under oath like that! He's the holiest man I've ever known!"
Her friend says. "He didn't. The book he's holding was Moby Dick."
The preacher comes by and says, "See you in church on Sunday," and the woman, who has never gone to that church in her life, becomes a lifelong faithful parishioner.
If I were a DM and a paladin PC tried something like this, I would have his god punish him with this level of discipline: "Mister Paladin, you did not lie under oath and betray your faith, but you did knowingly lie, and I cannot let that pass, even though you did it to stop a corrupt court system for punishing a woman whose only crime was defending herself from an evil man. You shall carry out an act of physical discipline to let the pain in your body remind you of your duty. Ready yourself in push-up position... now, give me... two. Two really good ones. Right. Let that be a lesson to you. I don't want to see you in here again."
I believe that in old 2e days, there were things like this for clerics who broke weapon-wielding rules in times of need. IE, cleric who pledged to only use blunt weapons uses a sword to stop the demon prince from destroying the world. Cleric's deity waits until after the fight and then delivers 1d4 damage to the cleric with a "don't let that happen again, coughcough". But if the cleric picks up an axe for a bar fight, when there is a club available as well, he gets immediately hit for a fair amount of damage (maybe 1d6/level) and loses all spellcasting abilities for a day.
It's a difference of degree and circumstance. A good player and a good DM can work it out.