Matt 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.
Matt 7:22; "Many will say to Me on that day, 'Lord, Lord, did we not prophesy in Your name, and in Your name cast out demons, and in Your name perform many miracles?'
Matt 7:23; "And then I will declare to them, 'I never knew you; DEPART FROM ME, YOU WHO PRACTICE LAWLESSNESS.'
I don't know any way to put this without touching on OSAS unfortunately. But there are at least a few views on this passage.
1. They never had the gifts of the Spirit ( they only thought they did ) and either never did any miracles, or else they did them by the power of demons.
I don't know of any place where anyone was healed by a demon in the Bible, however there are a couple of places where demons gave people the power to prophesy.
The Bible says Satan definitely doesn't cast out his own demons.
Acts 16:16; It happened that as we were going to the place of prayer, a slave-girl having a spirit of divination met us, who was bringing her masters much profit by fortune-telling.
Acts 16:17; Following after Paul and us, she kept crying out, saying, "These men are bond-servants of the Most High God, who are proclaiming to you the way of salvation."
Acts 16:18; She continued doing this for many days. But Paul was greatly annoyed, and turned and said to the spirit, "I command you in the name of Jesus Christ to come out of her!" And it came out at that very moment.
2. They were saved for a while, and actually did the miracles and cast out the demons, at least for a while, and then went back to "practicing lawlessness" ( iniquity, sin ).
3. There is of course the unbiblical view of cessationism ( they believe the gifts were only for the apostles in the first century ).
4. Most Pentecostal denominations ( for example the Assemblies of God ) believe that the "indwelling" of the Spirit is a different thing than the "baptism" of the Holy Spirit.
You receive the indwelling of the Holy Spirit at the instant you get saved. ( whether you keep it or not is another debate ), However the baptism of the Holy Spirit is a separate event.
In all five passages in Acts where people received the baptism of the Holy Spirit ( the vast majority were NOT apostles ) it happened some period of time after they were initially saved.
Most Pentecostal denominations would say you "should" be baptized in the Holy Spirit, but since you already have the indwelling of the Holy Spirit, it isn't a requirement in order to be saved.
Pentecostals believe the gifts of the Spirit are alive and well today. But in reality, there is sometimes too much emphasis on the "gifts", and not enough emphasis on the fruit.
It's not the Spiritual gifts ( 1 Cor 12:8-10; ) that determine your maturity as a Christian, it's the fruit ( Gal 5:22-23; ). If we look at the passage from Matthew 7 above, it's not
having/doing the gifts that saves you. There are some denominations that believe even if you "fall away" from salvation, you get to keep the Spiritual gifts until you die.
Some Calvinist denominations do not believe that the indwelling and baptism are two separate events. If this is true, then in all five passages where people received the baptism
of the Holy Spirit ( sometimes several years ) after their initial acceptance of Christ, they did not have the Holy Spirit at all, and therefore were not saved until they did.
Virtually all Calvinists believe you are "sealed" by the Holy Spirit until you die. ( Eph 4:30; ) Most of the more accurate translations say you were "marked" with a seal, rather
than you were "sealed". In either case, Calvinists would say you are "sealed" until you are ( safely ?? ) with Jesus. Some Arminians partially agree with this.
They would also say you are sealed until you die. However they would go with the more Biblical view, that you aren't "safe" with Jesus. This is when Jesus judges everyone
and the people who had the Holy Spirit to help them, will be held to a stricter judgment because they had no excuse not to live as Jesus lived.