David was not born again. He had the Holy Spirit upon Him, but not in Him. This was true of all prophets, some kings and judges in the OT when a specific task needed to be accomplished. Even the Apostles were not born again until after the cross. The Spirit of God could leave them in the OT. The permanent "in Him" presence which makes a person born again (regenerate) awaited the new Covenant that began to be realized at Pentecost (John 7:38-39). None of the regular believers had the Spirit upon them in the OT, let alone in them. They had the presence of God in the Temple. The Holy Spirit could not enter a believer unless there was blood to cleanse that Temple. No blood was available to cleanse the Temple of the Holy Spirit (1 Corinthians 6:19) until after the cross. The Holy Spirit indwelling is what places us into Christ, called the placing into with/by the Holy Spirit, otherwise known as the baptism with the Holy Spirit.
This was all a future promise realized at Pentecost, when a person could be placed into Christ, and thus, placed into His death and raised up with Him, born again. (Romans 6:3-11).
Ezekiel 36:26-27
I will give you a new heart and put a new spirit within you; I will take the heart of stone out of your flesh and give you a heart of flesh. I will put My Spirit within you and cause you to walk in My statutes, and you will keep My judgments and do them.
So, in the OT, nobody was indwelt with the Holy Spirit, thus we can rightly say that "there are none righteous, no not one, there are none who do good, no not one" (Romans 3), because that good, and true righteousness, is the fruit of the Spirit, not the flesh. They were owed that promise (Romans 8:28-30), a promise, a life, that begins with the Holy Spirit indwelling (Galatians 3:2-3), but they died having not received it (Hebrews 11:39-40, John 3:13-14).
We agree, that a person is saved by what Jesus did, but there needs to be clarity with the rest. Jesus said He will tell them who practice lawlessness, "I never knew you". interesting that the Bible says that those who love God are known by Him (1 Corinthians 8:3). Even OT believers (Romans 8:28-30). But He never knew them, meaning, they never loved Him.
Matthew 7:
"Not everyone who says to Me, 'Lord, Lord,' shall enter the kingdom of heaven, but he who does the will of My Father in heaven. Many will say to Me in that day, 'Lord, Lord, have we not prophesied in Your name, cast out demons in Your name, and done many wonders in Your name?' And then I will declare to them, 'I never knew you; depart from Me, you who practice lawlessness!'
David may have been a screw up at times, and failed at points in his life, much like we do, but make no mistake about it, he had a heart for God like no other. That's why God said that he does not want sacrifice, but He does except a broken and contrite heart (Psalm 51:16-17). That's what we call call 'poor in spirit' , the opposite of self righteousness (Matthew 5:3). Who was justified, but the broken and contrite heart of the tax collector, not the Pharisee who sacrificed by obeying the Law perfectly, albeit only perfect in his own mind (Luke 18:9-14).
Macarthur once put it so eloquently when he said that sin for a believer is a burden which afflicts him, rather than a pleasure which delights him." A true believer would have a strong desire to break away from all sin. He may struggle with it, as we all have the flesh that wars against the Spirit in us. But he would not say, "I'm justified, it doesn't matter." The latter would be an "evidence" that He was never saved.
If justification meant live any way that we want afterwards, then Paul is simply mistaken when He said.
1 Corinthians 6:9-10
Do you not know that the unrighteous will not inherit the kingdom of God? Do not be deceived. Neither fornicators, nor idolaters, nor adulterers, nor homosexuals, nor sodomites, nor thieves, nor covetous, nor drunkards, nor revilers, nor extortioners will inherit the kingdom of God.
Bypassing the delving into James 2 is like bypassing Jesus to uncomplicate the Gospel. We cannot separate them because each defines the other. And not understanding works as "evidences" conveniently removes the true definition of our works, as an evidence, and leaves only the two extremes, a works based salvation, or antinomianism. You can remove James, but there is still Paul, and you could remove Paul, but there is still Jesus, and you can remove the Bible, but there is still our conscience.
A broken and contrite heart that struggles, but desires and strives to get rid of sin is saved, just like the tax collector in the parable. To just say the heart doesn't matter, that all sin is forgiven is missing the importance of the part that our heart and motives play in that determining if our faith is genuine and we're justified by what Jesus did. Our works validate the genuineness of our hearts, our faith to us. God already knows.