I will offer a response to this question two ways:
- Assuming David was forgiven
- Considering the possibility that David was not forgiven
Assuming David was forgiven
The Lord’s words to Samuel put it very well:
the Lord seeth not as man seeth; for man looketh on the outward
appearance, but the Lord looketh on the heart (1 Samuel 16:7).
Two individuals may outwardly appear the same/similar, but God sees the truth inside that no outward show can hide. Appropriately then it is God’s prerogative to grant or withhold forgiveness of sin.
Paul spoke of the “godly sorrow” that leads to repentance in 2 Corinthians 7 (NIV):
9 yet now I am happy, not because you were made sorry, but because your sorrow led you to repentance. For you became sorrowful as God intended and so were not harmed in any way by us.
10 Godly sorrow brings repentance that leads to salvation and leaves no regret, but worldly sorrow brings death
The opposite of godly sorrow is worldly sorrow, which Dottard has already discussed as sorrow because of the punishment/consequence. This is not the kind of sorrow that leads a person to transformative change.
The pejorative language with which Judas is described in the Gospels/Acts does not suggest a man who was sincerely repentant for his grievous sin. David, on the other hand, does show tremendous sorrow--see Psalm 51:
1 Have mercy upon me, O God, according to thy lovingkindness:
according unto the multitude of thy tender mercies blot out my
transgressions.
2 Wash me throughly from mine iniquity, and cleanse me from my sin.
3 For I acknowledge my transgressions: and my sin is ever before me.
...
9 Hide thy face from my sins, and blot out all mine iniquities.
10 Create in me a clean heart, O God; and renew a right spirit within
me.
Note that David not only acknowledges his sin, but his focus is on what the Lord thinks, not what other people think. And David wants to be changed; he wants a clean heart. The point of repentance is not the sorrow, but the change that comes of it.
As Yael Eckstein observed:
we will know we have achieved true repentance when we choose not to
sin in circumstances where we might previously have sinned
David does not simply wish to have his sins taken away so he can continue as he was--he wants to fundamentally change. This is what is meant by "repent":
to turn from sin and dedicate oneself to the amendment of one's life (Merriam Webster, see here)
--
Considering the possibility that David was not forgiven
Not all exegetes hold that David was forgiven. After hearing Nathan's parable about his (David's) own sin:
And David’s anger was greatly kindled against the man; and he said to
Nathan, As the Lord liveth, the man that hath done this thing shall
surely die: (2 Samuel 12:5)
The Hebrew הֶעֱבִ֥יר חַטָּאתְךָ֖ לֹ֥א תָמֽוּת׃ from 2 Samuel 12:13 has also been taken to mean that David will be spared immediate punishment by death (the punishment he himself pronounced in verse 5), rather than indicating forgiveness of his sins. Psalm 16:10 “For thou wilt not leave my soul in hell” is itself rife with theological interpretation.
Psalm 32:5 does speak of forgiveness. Forgiveness of what sin? David committed adultery & murder and had pronounced (with an oath) the death sentence upon himself, and I am left to conclude that his standing before God is unclear. I am not his judge and do not claim to know.
The terrible irony is this - had David, after committing adultery, sincerely repented then and done all he could to make things right, perhaps only a handful of people would have ever known of his sin. But in an effort to hide his sin (fear of man more than fear of God), he committed murder -- and as a result his fall from grace is now recorded in the most widely disseminated book in human history.
His efforts to hide his sin resulted in it being known to billions. This does not describe a repentant heart or a godly sorrow. His later actions are for God alone to judge.
--
Did the Law of Forgiveness change in the New Testament?
The ordinances and sacrifices certainly changed (see Hebrews chapter 9), but it does not appear that human nature changed at all.
The command to repent is found clearly in both the Old & New Testaments (see, for example, Isaiah 55:7 & Matthew 4:17). If repentance is designed to change humans and develop them beyond their fallen nature (I submit that it is), repentance encompasses the same principles in the Old & New Testaments.
The penitence of repentance described by David in the Old Testament
The sacrifices of God are a broken spirit: a broken and a contrite
heart, O God, thou wilt not despise. (Psalm 51:17)
is beautifully matched by the godly sorrow described by Paul (see above).
As for forgiveness itself, Isaiah's promise is never abridged in the New Testament:
Come now, and let us reason together, saith the Lord: though your sins
be as scarlet, they shall be as white as snow; though they be red like
crimson, they shall be as wool.
I conclude that Jesus came not to make repentance & forgiveness forever obsolete, but to give the sacrifice that would make repentance & forgiveness eternally operative.