Bringing us back to the topic of the OP.
Matthew 7:21-23 NKJV
21 “Not everyone who says to Me, ‘Lord, Lord,’ shall enter the kingdom of heaven, but he who does the will of My Father in heaven. 22 Many will say to Me in that day, ‘Lord, Lord, have we not prophesied in Your name, cast out demons in Your name, and done many wonders in Your name?’ 23 And then I will declare to them, ‘I never knew you; depart from Me, you who practice lawlessness!’
There is another dynamic to look at when we examine this particular passage of scripture.
In the Hebraic understanding, to repeat something means that the individual truly believes in it. To repeat Lord, Lord means that these individuals of whom the scripture refers to, believe in Christ Jesus as Lord.
Casting out demons is an interesting point. We learn in scripture that the only way an individual can cast out a demon is if they have spiritual authority. Satan cannot cast out Satan. We learn with the itinerant Jewish exorcists, the 7 sons of Sceva, and a Jewish chief priest that if one is not in the Lord and operating by His power then they cannot cast out demons. What happened to these individuals who tried to cast out a demon by the Jesus whom Paul preaches? (Acts 19:11-20). The demon in the man specifically said, “Jesus I know, and Paul I know; but who are you?” This demon caused this man to leap on these individuals and prevail over them so they were forced to flee naked and wounded. causing many to fear the Lord and come to Him.
So if these individuals did cast out demons (and nothing in this scripture says that they didn't), then these individuals had to have been operating in spiritual authority and with the power of the Holy Spirit. What was it that caused Christ to tell them that He never knew them? The fact that they were practicing lawlessness. They had reached a point where Christ told them that He never knew them by their conduct and practices in their hearts. In essence, they were no longer doing the will of the Father in heaven, but the will of something else, be it self, the world, etc. How then can someone who operates with the power of the Holy Spirit to cast out demons, prophesy in His name, and do many wonders in His name not be someone who is in Christ Jesus?