There are different senses in which a person can be “known”. I can know that you exist and I can know something of your theological beliefs due to what you post here, and your responses to me. But I do not know you in the biblical sense of God, Christ, and the Holy Spirit know-ing people. I have never met you, never even seen a photo of you, nor do I know where you live and other personal details apart from those you choose to divulge on here. I know OF you, and ABOUT you (to a tiny extent), but I do not actually know you. There would have to be a meeting between us where we were mutually introduced before I could begin to think that I actually knew you.
Jesus made statements about how he knew people to enable us to grasp that, in the text in question, he was not referring to merely knowing of a person’s existence, or even knowing something about them. His ‘knowing’ is so deep that he can base his judgment of eternal damnation of some upon what turns out to be hypocritical deeds that fool others, but not Christ.
Check out what Jesus meant about knowing God and himself in John 16:3. He warned his disciples that they would be persecuted and even put to death: “And these things will they do unto you, because they have not known the Father, nor me.” Yet those persecutors knew full well, and believed in, God. They also knew of Jesus and his claims, to such an extent that they put him to death. The point here is that their knowledge of God and Jesus did not enable them to know God and Jesus, in the biblical sense of being saved by God, through faith in Jesus, which is enacted by the Holy Spirit. This is shown in John 17:3 where Jesus speaks of those who “know thee, the only true God, and Jesus Christ, whom thou hast sent.” Jesus did not mean a head-knowledge! He did not speak of those full of theology (knowing about God and himself). No, verses 6 and 7 show that those ones have kept God’s word, and have known that they are part of what God gave to the Son, which makes them “of God” – children of God, born of the Spirit, no less.
The Father and the Son know certain ones in an intimate, familial sense, because they have given those ones they know (in that saving sense) adoption into the very family of God (Romans 8:1-30). When a person experiences that miracle of grace, then they start to personally know Jesus even as they are known. “Now we see through a glass, darkly; but then face to face; now I know in part; but then shall I know even as I am known” (1 Cor. 13:12).
This pertains to answering your question because in Matthew 7:21-23 Jesus is speaking of the day of judgment (still future) when he demonstrates how he knows all those who belong to him as children of God by enabling them to enter the kingdom of heaven. Conversely, he demonstrates how he knows all those who do NOT belong to him, despite all their outward appearances of being Christians, even doing miracles and suchlike in Jesus’ name. He casts them asunder from his presence. He knows full well who they are, and what they are, but he does not know them as those with saving faith in himself.
While Jesus walked on this Earth, a woman touched the hem of his garment while crowds thronged him. He stopped, asking who had touched him. He knew that power of healing had gone out of him, now he needed to find the person with such faith. (Luke 8:44-48) He wanted to know that person in a personal way, and once she identified herself, he confirmed her faith and blessed her. So it is with all who place initial, active faith in Christ – he makes himself known to them personally, in a saving way. He does not instruct them to study reams of theology books to learn about him. No, he tells those repentant ones to go in peace, for their faith is blessed, and they have begun to personally know Jesus, who personally knows them.
With Nathaniel, it was the other way around. Jesus knew he was sitting under a fig tree before Philip called him to meet Jesus. He also knew that Nathaniel was a man without guile, which astonished Nathaniel, for he exclaimed, “How do you know me?” Jesus’ answer convinced Nathaniel that this was, indeed, the Son of God, the King of Israel (John 1:43-51). There is demonstrated Jesus’ foreknowledge of an individual whom he called to be his disciple.
Thus those myriads who Jesus calls into the kingdom of heaven are known personally by him before they are called. Romans 8:28-35 shows that they are “called according to his purpose”. Because they were foreknown, they are predestined “to be conformed to the image of his Son”, to become Christ’s brothers.
“Moreover whom he did predestinate, them he also called; and whom he
called, them he also justified, them he also glorified.”
“Elect according to the foreknowledge of God the Father, through
sanctification of the Spirit, unto obedience and sprinkling of the
blood of Jesus Christ” (1 Peter 1:1-5).
That is what it means to be personally known by Jesus. But in Matthew 7:21-23 Jesus does not know the ‘workers of lawlessness’ as his beloved brethren; he knows them to be hypocrites. This text is not speaking of the future day of judgment as if Jesus gets to see people he never knew before – knowing them for the first time then. No, he knows all about them even while they live and die on Earth, but he refuses to know them as his brothers, because their father is not God, but the devil, as he pointed out to religious hypocrites of his day, in John 8:31-45.
But how could Jesus NOT know all his brothers, no matter how many of them there are? This Jesus is not finite, limited in ability to understand, have knowledge, or to know people! To be personally known by Jesus requires a personal meeting where the Holy Spirit introduces the person to Christ, who already knew they were to be called to saving faith, just as Nathaniel personally met Jesus, discovering then that Jesus had already decided to call him, because he knew Nathaniel personally beforehand.