Peace be on to you all.
I think that the answer lies in the context...
two verses before Jesus says and I quote from Matthew chapter 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."
(here Jesus is explaining that God is the one who is in control of heaven and hell and not Jesus because Jesus clearly states that you must submit to the wil of God.)
then vers 22' "Many will say to me in that day (day of judgement), 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?"
(now in this verse he is adressing the problem of those people, they are forgetting the true God in heaven and concentrating only on Jesus. who is A messenger of God.)
and now verse 23' And then will I profess unto them, I never knew you: depart from me, ye that work iniquity.
(He clearly describes the problem and gives an answer to it, because how can you pray to an image of man and forget the One True God in heaven..)
Hi zengi, Welcome to the forums.
True! You started off correct---the context does give the answer to the question, but then didn't continue with the meaning given in the contextual scope of the sermon on the Mount.
Jesus came to "fulfill the Scriptures" which were written concerning HIM. "To seek and save" lost mankind---and eventually to make all things new--back to a right relationship to the Father.
Jesus has shown the activities and philosophies which are displeasing and do separate one from the WILL of the Father. Then HE differentiates between actions of what isn't know about another's short-comings and those which one knows to be contrary to the character of the standard--GOD.
That "seeking and saving" was/is freely extended to all who choose to have GOD as their GOD. (2Pet.3:9) GOD is "long-suffering not willing that any should perish, but that ALL should come to repentance". The exclusion is in the person's own choosing--the rejecting of the Father's WILL and doing of that which is displeasing to GOD. It is called arrogance/defiance. That attitude is contrary to the harmony seen in the LOVE which is at the foundation of GOD'S Government.
Therefore, (vs.21) when "that day arrives" and it is time "to enter into the kingdom of heaven"---And GOD does know those who are HIS(Num.16:5; 2Tim.2:19)--- there will be those who have been deluded into following the prophesied false GOD seen in 2Thess.2:3-4 and is seen in Rev.18:4("Come out of her my people".) They heard the message, but chose to remain( just as Eve chose to believe the serpent rather than GOD).
Therefore, their works were not to please GOD , but their own self-righteousness. and Jesus' Blood isn't upon them as evidence that they are HIS.
The recording is Just, Right, Merciful and Gracious made in LOVE. Just as Cain was sent away from Eden.