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.In verse 22, Jesus notes that many, not just some, will find themselves at the last day thinking that all this time they had thought they were doing many wonderful works in the name of God and find out that Jesus does not recognize them or their works. All kinds of atrocities are committed in the name of piety: "whosoever killeth you will think that he doeth God service." (John 16:2). A thoughtful Christian probably should be doing as the apostles did, becoming "exceeding sorrowful, and began every one of them to say unto him, Lord, is it I?" (Matthew 26:22).
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)
The passages immediately preceding and following this section from the Sermon on the Mount help to set it in context. The one before says:
15 Beware of false prophets, which come to you in sheep’s clothing, but inwardly they are ravening wolves.
16 Ye shall know them by their fruits. Do men gather grapes of thorns, or figs of thistles?
17 Even so every good tree bringeth forth good fruit; but a corrupt tree bringeth forth evil fruit.
18 A good tree cannot bring forth evil fruit, neither can a corrupt tree bring forth good fruit.
19 Every tree that bringeth not forth good fruit is hewn down, and cast into the fire.
20 Wherefore by their fruits ye shall know them. (Matthew 7:15–20)
Jesus tells his followers that there will be false prophets (and we should remember that the term for prophet in both Greek and Hebrew meant spokesman--a prophet is a spokesman for God) who will come to them. The term translated as ravening has alternate translations of presumptuous (if you are looking at Syriac) or rapacious, usurping (if you are looking at Greek). They can be recognized by their fruits, that is, their works. Are they productive, peaceable, good, or are they contemptible, clandestine, corrupt?
In the following section, Jesus says:
24 Therefore whosoever heareth these sayings of mine, and doeth them, I will liken him unto a wise man, which built his house upon a rock:In Matthew 7:21-23 and Matthew 7:24-27 the emphasis is on those who actually do the will of God. That will of God is announced by prophets, but not false ones.
25 And the rain descended, and the floods came, and the winds blew, and beat upon that house; and it fell not: for it was founded upon a rock.
26 And every one that heareth these sayings of mine, and doeth them not, shall be likened unto a foolish man, which built his house upon the sand:
27 And the rain descended, and the floods came, and the winds blew, and beat upon that house; and it fell: and great was the fall of it. (Matthew 7:24–27)
Still a Christian ought to ponder, at least occasionally, that it takes more than claiming that one is a Christian to be recognized as one by Christ.