Jesus did actually say He never knew those who believed in Him in Matthew 7:21-23. Then He went on to explain the importance of laying a proper foundation. I don't believe this was a coincidence. His immediate explanation would seem to indicate the lack of a proper foundation was the reason He had NEVER come to know them. Note what is included in the foundation as revealed in Hebrews 6 below.:
"Therefore leaving the principles of the doctrine of Christ, let us go on unto perfection; not laying again the foundation of repentance from dead works, and of faith toward God,
Of the doctrine of baptisms, and of laying on of hands, and of resurrection of the dead, and of eternal judgment." Heb 6:1-2
Each item mentioned, is included in Peter's initial message presented at Pentecost. (Acts 2:4-42) I don't believe this is a coincidence either. I believe it is possible they were never buried together with Jesus. Surely Jesus knows those who believe and buried together with Him through faith and obedience to the NT water baptism command.
2Ti 2:19 Nevertheless the foundation of God standeth sure, having this seal, The Lord knoweth them that are his. And, Let every one that nameth the name of Christ depart from iniquity.
2Ti 3:4 lovers of pleasures more than lovers of God;
2Ti 3:5 Having a form of godliness, but denying the power thereof: from such turn away.
2Ti 3:7 Ever learning, and never able to come to the knowledge of the truth.
Mat 7:21 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.
Mat 7:23 And then will I profess unto them, I never knew you: depart from me, ye that work iniquity.
They would not allow the Spirit to lead them and lived in sin believing they were saved so they never came to the knowledge of the truth.
Heb 10:26 For if we sin wilfully after that we have received the knowledge of the truth, there remaineth no more sacrifice for sins,
Heb 10:27 But a certain fearful looking for of judgment and fiery indignation, which shall devour the adversaries.
If a person holds unto sin then the blood of Jesus will not wash it away because God will not take away a sin they hold on to and they are truly not repenting.
Gal 5:16 This I say then, Walk in the Spirit, and ye shall not fulfil the lust of the flesh.
Gal 5:22 But the fruit of the Spirit is love, joy, peace, longsuffering, gentleness, goodness, faith,
Gal 5:23 Meekness, temperance: against such there is no law.
Gal 5:24 And they that are Christ's have crucified the flesh with the affections and lusts.
Gal 5:25 If we live in the Spirit, let us also walk in the Spirit.
1Co 10:12 Wherefore let him that thinketh he standeth take heed lest he fall.
1Co 10:13 There hath no temptation taken you but such as is common to man: but God is faithful, who will not suffer you to be tempted above that ye are able; but will with the temptation also make a way to escape, that ye may be able to bear it.
A Spirit led life will not sin therefore they are not under the law which the law cannot touch them for prosecution.
There is no excuse although many people make an excuse and are under the law thinking they are not.