Step back and see the whole passage as one unit. Verse 21 says the mark of a real disciple is doing the Father’s will. Verse 23 says the mark of a real disciple is being known by Jesus. These are not two different tests; they are one reality seen from two sides. The obedient life and the known heart are the same thing. Jesus is closing His sermon by pressing us past our words and past our works to the only ground that will hold, a real relationship with Him.
Notice the two words that change everything: on that day. The verdict I never knew you is spoken on the last day, the day of judgment. And the good news this morning is that this is not that day. This is still today. Right now the very same Jesus who will one day sit as your Judge is standing as your Savior, and His arms are open wide. Christ came for people who cannot save themselves. He lived the life of perfect obedience we could never live, and at the cross He absorbed the sentence we deserved. He heard depart from me so that we would never have to hear it. He was cast out so that we could be brought in.
So you do not enter the kingdom by impressing the Judge with your speeches, or by overwhelming Him with your accomplishments. You enter by being joined to His Son, whom the Judge already knows and already loves. When the Father looks at you hidden in Christ, He does not say, I never knew you. He says, this is My beloved child, and I know him well. If you belong to Jesus, that is your name today and forever. So do not rest on what you say or on what you do. Come to Christ, be found in Him, be known by Him, and then out of that relationship, and only ever out of that relationship, go and do the will of your Father who is in heaven.