These people profess Christ's name. They take it for themselves and do these so-called works, in which they seem to preach, prophesy, do good works like casting out demons, and perform wonders. Yet, what does Jesus say? "I never knew you."
What did they profess? They professed to know God and have a relationship with Him, but He says, "I never knew you, because really you never knew Me." How does He know that? They were practicing lawlessness!
What is lawlessness? Sin! These people lack obedience. They may have the knowledge, but they lack putting this knowledge into godly practice. They believe that they know God's will, but they do not do it. Failing to practice God's will, Jesus says, is sin. Why is failing to practice God's law sin? Because, if we are not doing God's will, we are certainly doing something else!
What is not of God is sin (compare Romans 14:23)!
They have not hit the mark, which is one of the definitions of sin. Obviously, their problems originate in the way they think. If their thoughts were godly, they would behave in a godly manner. However, since they do not behave in a godly manner, their thoughts must not really be godly.