If you read on in Matthew 7:23 it says "...depart from Me, ye that work iniquity."You must include verse 21 in Matthew 7
“Not every one that saith unto me, Lord, Lord, shall enter into the kingdom of heaven; but he that doeth the will of my Father which is in heaven.
What is “the will of the Father”? The answer is found in John 6:40..
“And this is the will of him that sent me, that every one which seeth the Son, and believeth on him, may have everlasting life: and I will raise him up at the last day.”
The group in Matthew 7:21-23 were unsaved because they refused to do God's will concerning salvation. It wasn't because they still had personal sins in their life. Every believer still has sin in their life! We all sin every day. That's not to say that we have God's approval to sin, God forbid (Romans 3:31). It just means that even the best of Christians are still sinners.
If you think that forsaking sins was necessary for you to be saved, then you have religion, but you have never been born again!
2 Tim 2:19 "Nevertheless, the foundation of God standeth sure, having this seal, The Lord knows them that are his. Let every one that nameth the name of Christ depart from iniquity".
It also says in Eph 5:3 "But fornication, and all uncleanliness, or coveteousness, let it not be named ONCE among you as becometh saints;"
Eph 5:3 is more strongly worded compared to Gal 5:19-21 because here it's not even talking about a lifestyle, but even a single act or doing it once AFTER becoming a Christian.
2 Cor 12:21 "And lest, when I come again, my God will humble me among you, and that I shall bewail many which have sinned already, and have not repented of the uncleanliness and fornication and lasciviousness which they have committed".
The Apostle Paul, the biggest grace teacher has a very strong words concerning fornication. He is saying this is not to be committed once a person becomes a Christian (Eph 5:3). He is saying that Christians should depart from iniquity if they are saying they are Christians (1 Tim 2;19), and he is also crying over people in the Corinthian church who have not repented from fornication. For the same author that says Eph 2:9 "By grace you are saved, it is a gift of God", to also write these as well, means the evidence that you are saved or have made a serious commitment that reflects a true convert is that you depart from sin.
Otherwise, ask yourself, why would Paul bewail the unrepentant fornicators in the Christian church? Would he not celebrate and say they are saved by grace? What happened to Eph 2:9 there?