Matthew 7:21-23
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.
22 Many will say to me in that day, Lord, Lord, have we not prophesied in thy name? and in thy name have cast out devils? and in thy name done many wonderful works?
23 And then will I profess unto them, I never knew you: depart from me, ye that work iniquity.
The Grace New Testament Commentary - Matthew 7:21-23
7:21 A profession of Jesus as Lord will not guarantee entrance into the kingdom by itself. Those who still cling to their pharisaical righteousness but profess Christ will not make it. Only those "who [do] the will of [the] Father" will "enter the kingdom of heaven." The will of the Father may be viewed from two perspectives. Jesus' interpretation of the Law is the Father's will. But to do this for entrance into eternal life requires perfect obedience (5:48; Luke 10:25-37; Rev 21:27). This door, practically speaking, is shut. But there is still another way! Jesus said in John 6:40, "'And this is the will of Him who sent me, that everyone who sees the Son, and believes in Him, may have everlasting life; and I will raise him up at the last day.'" The will of the Father is to believe in the Son. Obeying the will of the Father in this manner brings salvation.
7:22-23 The individuals in vv 22-23 do not do the will of the Father. Although they claim to have performed supernatural "'wonders in [Christ's] name,'" at the Great White Throne Judgment ("in that day") they will be convicted as those "who practice [or do] lawlessness." Jesus will declare, "'I never knew you; depart from Me.'" These verses do not refer to people who once performed works only a saved person could do and then lost their salvation. The verses are referring to those whom Christ never knew. These were counterfeit believers, not real ones. Whether they actually performed supernatural wonders or not remains unclear. If they did perform such works, it could not be from Christ, but must have been of Satan. If they did not, they are simply fabricating an experience they never had.
The Henry Morris Study Bible - Matthew 7:23
7:23 These false prophets are not people who were once saved and then became apostates. Christ never knew them.