1 Corinthians 5:9-13: "I wrote you in my letter not to associate with immoral people; I did not at all mean with the immoral people of this world, or with the covetous and swindlers, or with idolaters, for then you would have to go out of the world. But actually, I wrote to you not to associate with any so-called brother if he is an immoral person, or covetous, or an idolater, or a reviler, or a drunkard, or a swindler—not even to eat with such a one. For what have I to do with judging outsiders? Do you not judge those who are within the church? But those who are outside, God judges." NASB
So it is clear that we need to judge those who are in the church, but we need to be very careful when we do so, because:
Romans 2:1-3: "Therefore you have no excuse, O man, every one of you who judges. For in passing judgment on another you condemn yourself, because you, the judge, practice the very same things. We know that the judgment of God rightly falls on those who practice such things. Do you suppose, O man—you who judge those who practice such things and yet do them yourself—that you will escape the judgment of God?" ESV