One of the realizations I came to about this passage, because it can be troubling, is that Jesus was talking to Jews, His people.
Notice that they referred to the judge as 'Lord' which is the word they use to refer to YHVH. But it is YHVH ( Jesus) who is speaking to them in the flesh, whom they reject.
So, Jesus is telling them that their refusal to receive Him as YHVH will result in Him denying that He knows them.
Hence, it is not sufficient to believe in God or do works in service to God. What is critical is that we know God and He knows us.
Jesus said He is the Truth. He is God and there is no other.
The Jews failure to receive Jesus as God in the flesh has doomed 80 generations of Jews!
For those believers who may be unnerved by this passage, they need to just listen to this: "And whosover will call on the name of the Lord Jesus Christ shall be saved."
The name of Jesus is not negotiable. His is the name and there is no other name whereby we may be saved.
This is what condemns Jewry and condemns every man that comes into the world - the denial that Jesus is Creator, Mighty God, Savior, Lord, King and Righteous Judge.
If you have believed on Jesus and received Him as your Lord, God and Savior, you are 'accepted in the Beloved'. You are in Him and He is in you. And so, He knows you and you know Him.