Man's perversion of Matthew 7:21-23 to justify self-righteousness through Law...
21 “Not everyone who says to Me, ‘Lord, Lord,’ will enter the kingdom of heaven, but the one who does the will of My Father who is in heaven will enter. 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 [s]miracles?’ 23 And then I will declare to them, ‘I never knew you; leave Me, you who practice lawlessness.’ Matthew 7:21-23 (NASB)
You err in your interpretation of Matthew 7:21-23. Jesus, in this discourse, is approached by those who cite their worthiness via their good works done in the Name of our Lord yet Jesus rejects them and tells them He never knew them...how can this be?
These people, in their self-righteousness, relied upon their works to please the Father and earn their own way into the Kingdom and Jesus plainly tells them that they NEVER entered into covenant relationship with Him or the Father by faith as they never relented to the Father's will; that is, "to believe in the One He has sent into the World" to provide blood atonement for sin (John 6:29); therefore, Jesus said I don't know you...depart from me you who work iniquity.
Those works that are done apart from covenant relationship by faith in Jesus are equated by the Father as filthy rags (a bloody menstrual cloth in the Hebrew)...they mean NOTHING (Isaiah 64:6) until such time an individual trusts in Jesus and establishes covenant relationship and receives the indwelling Holy Spirit and ONLY those works done by and through the Spirit please the Father and validate one's faith as legitimate. It is by faith, alone, in Jesus, alone, that the Father is pleased (1 John 2:23).