We must not judge a person's character and motives. Those things are none of our business. Also, we must not pronounce a verdict on others (Mt 7:2). Nor should we sentence them to punishment. We are not to judge in these ways.
We must judge whether or not people have specks in their eyes, that is, we should judge if they are sinning. We must do this in order to remove the specks from their eyes after we have removed the planks from our own eyes (Mt 7:4). The Lord commands us: "If I say to the wicked man, you shall surely die; and you do not warn him or speak out to dissuade him from his wicked conduct so that he may live: that wicked man shall die for his sin, but I will hold you responsible for his death" (Ez 3:18). The Lord also commands: "Anyone who sees his brother sinning, if the sin is not deadly, should petition God, and thus life will be given to the sinner" (1 Jn 5:16). Thus we must judge what is right or wrong. We must judge, condemn, and hate sin. We do this not because we have judged sinners but because we love them.
Thus, we are responsible to judge sin, not sinners. We must do this to love sinners by removing the specks from their eyes. Judging sin is necessary for loving others. Judging people is an obstacle to loving them. Judge so as to love.