What is the meaning of Matthew 7:21-23 KJV?

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. (Matthew 7:21-23 KJV)

Thomas Scott

Verses 21-23: Christ, on this occasion, spake not only as avowedly the King of Israel, the promised Messiah, but with the dignity and authority of the Judge of the world, and the Arbiter of every man’s eternal state, from whose decision there could be no appeal; and when we compare this language of conscious majesty and power, with his lowly appearance and external circumstances, and the neglect and contempt to which he was exposed, the contrast is peculiarly striking.

—It is implied, that they who do not acknowledge him as their Lord and Master, are not even  professedly in the way to Heaven: and it is declared, that even of his professed disciples and subjects who acknowledge him for their Ruler, Teacher, and Saviour, and openly avow their relation to him, some will be excluded from the kingdom of heavenly glory as not having, been true subjects of his kingdom of grace and that they, “who do the will of his heavenly Father,” shall be finally and eternally saved.

—It is here indispensably necessary to distinguish between the will of God, the Creator and Lawgiver, concerning his rational creatures; and his will as it concerns us fallen and condemned sinners. The law of “loving him with all our hearts,” “and our neighbor as ourselves,” without the least allowance for failure, and sanctioned with the most awful curse, is, in the former sense, “the will of God.” This “shuts up all men under sin and condemnation;” but God is now become the Saviour of sinners.

What then, in revealing himself to sinners as a God of salvation, is his will concerning them? For this is here exclusively spoken of as “the God and father of our Lord Jesus Christ,” it is his will that we should repent, forsake and hate all sin: believe, submit to, love, and obey his only begotten Son; love one another, and walk in all his ordinances and commandments with an upright heart. His first requirement in this view is, “This is my beloved Son, in whom I am well pleased, hear ye him.”

When this is complied with, all else follows; without it, all else is in vain. Obedience in all things is sincerely attempted, and habitually performed, in the general tenor of the true believer’s life, from the time that he comes as a sinner to accept of Christ’s salvation. In the sense he does the will of God; though he is far from being able to do his will as the absolute Governor of the world, in such a manner as to be justified by the work of the law. But hypocrites do not sincerely attend to this will of God; and therefore they shall never enter Heaven. Nay, the Lord declares that many, “in that day” (the solemn day of final account and retribution), even of such as have preached the gospel, prophesied in his name, wrought miracles, cast out devils, will be rejected by him, because they were workers of iniquity.

Not only a single Balaam who prophesied, or a single Judas and apostle, will be thus condemned; but many will plead in vain their profession, gifts, and services, and the miracles which they have wrought in the name of Jesus Christ. He will then disavow all knowledge or approbation of them as his disciples or servants; he knew them as hypocrites, but he did not accept them: He “never knew them,” they were all along hypocrites and workers of iniquity. They therefore will be constrained to depart from the holy Saviour (whose name they had used and profaned), with other workers of iniquity, to their own place, under the most aggravated condemnation; Mt 25:41-46 for, in departing from Christ, the Light and Life of men, they must sink into darkness and despair.