Its all about the intent. Jesus did not associate with sinners because he liked their company or actions. He wanted to given them an opportunity to change course and leave the sinful behavior behind. His admonition was "go and sin no more".
In Acts 3, Peter had just healed a lame man and the Jews were amazed.
"And when Peter saw it he addressed the people: “Men of Israel, why do you wonder at this, or why do you stare at us, as though by our own power or piety we have made him walk? 13 The God of Abraham, the God of Isaac, and the God of Jacob, the God of our fathers, glorified his servant Jesus, whom you delivered over and denied in the presence of Pilate, when he had decided to release him. 14 But you denied the Holy and Righteous One, and asked for a murderer to be granted to you, 15 and you killed the Author of life, whom God raised from the dead. To this we are witnesses. 16 And his name—by faith in his name—has made this man strong whom you see and know, and the faith that is through Jesus has given the man this perfect health in the presence of you all.
17 “And now, brothers, I know that you acted in ignorance, as did also your rulers. 18 But what God foretold by the mouth of all the prophets, that his Christ would suffer, he thus fulfilled. 19 Repent therefore, and turn back, that your sins may be blotted out" (Acts 3:12-19 ESV)
Obviously Peter was giving a witness about the power of God's spirit to heal physically, but the highlighted part of the passage has great meaning. Acting in ignorance is one thing, but willful and deliberate sin is inexcusable. Repentance requires a turning back from a sinful way of life. This is how we demonstrate our love for God and our willingness to obey his commands. A momentary lapse in judgment is not the same as willful disobedience. Sins are "blotted out" only if the repentance is genuine. God can read hearts, so we can't fool him or presume on his mercy.
If you notice in 1 Corinthians 5, Paul said that the congregation shepherds were to "judge" those "inside" the congregation.....this means that willful sin has become known and the shepherds are under obligation from God to call the sinner out and judge whether what has become known is true or not. They will pray for and about the erring one, but they cannot allow sentiment to cloud their judgment, nor can they allow a willful sinner to remain in the congregation in good standing, because "a little leaven ferments the whole lump."
Hebrews 13:17:
"Obey your leaders and submit to them, for they are keeping watch over your souls, as those who will have to give an account. Let them do this with joy and not with groaning, for that would be of no advantage to you."
The shepherds are accountable to God for needed discipline. (Hebrews 12:5-6) They were to expel that one after many attempts to lovingly lead them to repent......the unrepentant one was not permitted back into the congregation until repentance was demonstrated. The discipline is not cruel, but loving. Do we not discipline our own children because we love them?
Genuine repentance comes from the heart and is the very basis for forgiveness. Jesus' compassion was not a license to sin, presuming on God's forgiveness.
If you remember the parable of the prodigal son....? The father made no attempt to contact the erring son whilst he was living a debauched life and squandering his inheritance, but once he came to his senses, and humbly returned with a contrite heart, the father ran to meet him. The return had to come from a learned lesson, and painful and all as it was, the lesson led him back to his Father....who welcomed him back with open arms and tears of joy.