It can be seen as a form of virtue signaling or a way to display one's moral superiority over others.
One could identify various examples of this behaviour in the political sphere, where politicians or public figures present themselves as morally upright while engaging in unethical or morally questionable actions behind the scenes.