I also think the quote from James in my signature is relevant to Jesus' point here. Jesus is talking primarily about identifying false teachers, I think, in context. The Pharisees were probably who he had in mind in particular
Herein lies your answer. I used to think this meant good vs bad works until I realized who Christ was rebuking. The pharisees did 'good works' of Law. In fact, Christ Himself said unless ones righteousness exceeds theirs, they cannot enter the kingdom. What I am now convinced of is this has little if anything to do with outward works, but specifically about confession of believing the truth. Hence a bad tree, a reprobate or unregenerate, cannot confess any truth. Yet a good tree, elect/regenerate of God, will produce this good fruit. Think of how many non believers or false believers are morally superior to Christians at times. I worked with a Mormon who did so many good works, that I began to doubt my conversion. Then I know the difference. What is the only fruit that separates a believer from a non believer? Belief in the truth.
Matthew 7:13-23 is often cited to support the false doctrine that one must evidence one's salvation by works in order to prove that one is saved or even to do such works as part of what one must do to be saved; otherwise one is not truly saved at all. But is this what Christ is really saying? The gospel's enemies usually conceal their hostility and try to pass themselves off as fellow believers. At first glance they use orthodox language, show biblical piety, and are indistinguishable from true prophets. "them" = the false prophets, the subject of this passage, (v. 15), who could be unbelievers or believers who teach false doctrine.
John RObbins said:
They will not acknowledge the Satisfaction and Atonement of Jesus, because they do not believe it. Their prayer will not be, 'God, be merciful to me a sinner,' but, 'Jesus, I did many wonderful works in your name, and now you ought to reward me with Heaven.' Whatever these churchgoers and church leaders may believe about themselves and about Jesus, they do not believe in their own depravity, nor in the imputed righteousness of Christ. They do not believe that the only way to Heaven is through Jesus Christ. In short, they do not believe the Gospel, and that is why they are damned.
The vivid warning that Jesus gives us in this passage is not merely about the futility of working for salvation. It is also a warning about believing some things about God and Jesus, but not believing the Gospel. James tells us that demons believe in one God—and they are lost. That means that monotheism per se will not save anyone. Mark tells us that one demon recognized Jesus as the Holy One of God, and that demon was lost. That means that acknowledging Jesus as the Messiah per se will not save anyone. (And if anyone suggests that it is obedience that makes faith saving, it seems that no one obeys Jesus Christ more quickly in the New Testament than the demons to whom he speaks.)
Paul picks up on this point in Galatians, where he damns everyone, man or angel, who brings a message other than justification by faith alone. Presumably the false teachers in Galatia who were urging the Christians there to supplement their faith with works not only believed in God and in Jesus as the Son of God, but in the infallibility of the Scriptures (the Old Testament) and in Jesus’ miracles as well. Perhaps they even believed in his resurrection. But a belief in Jesus’ resurrection per se will save no one.