1Cor 5:12,13 What business is it of mine to judge those outside the church? Are you not to judge those inside? God will judge those outside. "Expel the wicked man from among you." (Deut 17:7)
Paul, quoting Deuteronomy, shows an application of the Law.. The Law of Moses is not irrelevant to the Christian life. Though we are not bound to its regulations we are to infer appropriate applications from its commands.
Those outside the church already stand in judgement - a judgement that in fact they have to be saved from. For "Whoever believes in him is not condemned, but whoever does not believe stands condemned already" John 3:18 and "Whoever believes in the Son has eternal life, but whoever rejects the Son will not see life, for God’s wrath remains on him." John 3:36 It is not our business to judge them. For they already stand condemned. Our business is to save them.
But as for those who allege to be saved, namely those alleging to be Christians, that's a different story. Christians are to judge other Christians. And forgiveness is not unconditional among Christians, but requires that the fellow Christian confess their sins, as Jesus said in Matt 18:15-17, or else be disassociated from.
The church has suffered much from the abuse of this concept. In earlier centuries churches often expelled Christians on an illegitimate basis over issues like baptism, some even being murdered. Though today we tend to face the opposite problem where institutional leadership is complacent with regards to this instruction forcing the saints to associate with alleged brothers living a lifestyle of sin. And predictably a little leaven leavens the whole batch.
The Berean Christian Bible Study Resources