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: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?
Mat 7:23 And then will I profess unto them, I never knew you: depart from me, ye that work iniquity.
Jesus did not rebuke them for doing works to earn salvation,but they were workers of iniquity,which they did not do the will of the Father.
In regards to Matthew 7:21-23, I'll never forget, prior to my conversion several years ago, while still attending the Roman Catholic church, I read Matthew 7:22 and thought to myself, wow! These many people accomplished all of that, "prophesied in His name, cast out demons, and did many wonderful works" but that still was not
"good enough?" Then I thought to myself at that time, how am I going to "top that" and be "good enough?" Such is the mindset of someone who believes that salvation is by works.
Matthew 7:21 - Not everyone who says to Me, 'Lord, Lord,' will enter the kingdom of heaven, but he who
does the will of My Father who is in heaven will enter.
John 6:40 - For
my Father’s will is that
everyone who looks to the Son and believes in Him shall have eternal life, and I will raise them up at the last day.
These many people (unbelievers) in Matthew 7:22 had the wrong foundation. They were trusting in their works to save them and NOT IN CHRIST ALONE. Jesus
never knew them which means they were
never saved. Their hearts were not right with God, so their attempted external obedience was stained with sin. *Seeking salvation by works is not the will of the Father.
John 17:3 - And this is eternal life, that they may
know You, the only true God, and Jesus Christ whom You have sent. The term "know" implies intimate, experiential knowledge, through a relationship with Him, not merely theoretical knowledge. These many people were not true converts.
Without faith it's impossible to please God no matter how many alleged wonderful works that these many people set out to conjure up through the flesh. This is why Jesus referred to them as WORKERS OF INIQUITY/LAWLESSNESS! They were self righteous. There are false prophets who prophecy in the name of Jesus and even make false prophecies.
Also, Satan may grant the power to one of his agents to cast out demons from another of his agents in order to gain attention and loyalty from an audience for his evil agenda. False teachers and false prophets have long demonstrated supernatural power granted by Satan, including the power to control the demonic realm. The enemy uses this deception to win an audience for his claims.
Also, in Matthew 10:1, we also see that Jesus gave His 12 disciples power over unclean spirits, to cast them out, and to heal all kinds of sickness and all kinds of disease. This would include Judas Iscariot, yet Jesus referred to Judas Iscariot as an
unbelieving, unclean devil who would betray Him (John 6:64-71; 13:10-11).
Apparently, Judas believed that Jesus' name has the power to cast out demons but did not truly believe in His name (John 1:12) and become a child of God, but instead was the son of perdition (John 17:12).