My "understanding of this passage" is the same as Mark E. Ross, Erskine Theological Seminary.

“Jesus takes us to the last day, to the judgment at the end of history. In that day, he says, there will be many who have called him ‘Lord’ that will not enter the kingdom of heaven. Why not? Two reasons are given. First, Jesus did not ‘know’ them. That is, there was no personal relationship between Jesus and these false followers. Though they called Jesus ‘Lord’, prophesied in his name, cast out demons in his name and performed mighty works in his name, he had no personal relationship with them. Second, they were workers of ‘lawlessness’. That is, they did not follow the teaching of Jesus and they did not keep the law of God. Notice that as the sermon draws to a close Jesus has returned to the importance of keeping the law. He is not, of course, teaching that salvation is by keeping the law. But he is saying that those who are saved will be known by their fruits, and their fruits will include obedience to the law of God. Theirs will not be a religion of just saying that they follow Jesus, while doing some works in his name. No, their religion will be one of following Jesus, of doing all that he says and commands. They are not like those who James tells us say they have faith, but they have not works. The true followers of Christ can be known because their works show that they have faith (James 2:14-26).” (Ross, 2009)

Ross, Mark E. (2009) “Let’s Study Matthew” Chapter 34, The Banner of Truth Trust, Pg. 75