It was at their insistence that Jesus gave his sentence; and so the Evangelist says, As they persisted in the question, he stood up and said to them: Whoever among you is without sin, let him be the first to cast a stone at her. The Pharisees were violators of the Law; and yet they tried to accuse Christ of violating the Law and were attempting to make him condemn the woman. So Christ proposes a sentence in accord with justice, saying, Whoever among you is without sin. He is saying in effect: Let the sinner be punished, but not by sinners; let the Law be accomplished, but not by those who brea...k it, because "When you judge another you condemn yourself" (Rom 2:1). Therefore, either let this woman go, or suffer the penalty of the Law with her.
Here the question arises as to whether a sinful judge sins by passing sentence against another person who has committed the same sin. It is obvious that if the judge who passes sentence is a public sinner, he sins by giving scandal. Yet, this seems to be true also if his sin is hidden, for we read in Romans (2:1): "When you judge another you condemn yourself." However, it is clear that no one condemns himself except by sinning. And thus it seems that he sins by judging another.
My answer to this is that two distinctions have to be made. For the judge is either continuing in his determination to sin, or he has repented of his sins; and again, he is either punishing as a minister of the law or on his own initiative. Now if he has repented of his sin, he is no longer a sinner, and so he can pass sentence without sinning. But if he continues in his determination to sin, he does not sin in passing sentence if he does this as a minister of the law; although he would be sinning by doing the very things for which he deserves a similar sentence. But if he passes sentence on his own authority, then I say that he sins in justice, but from some evil root; otherwise he would first punish in himself what he notices in someone else, because "A just person is the first to accuse himself" (Prv 18:17).
Source: Commentary on John