Ironically, David's sin is one of the two examples that Paul uses in Romans 3 and 4 to show that Christ died for all sins for all time.
21 But now apart from the Law the righteousness of God has been manifested, being witnessed by the Law and the Prophets,
22 even the righteousness of God through faith in Jesus Christ for all those who believe; for there is no distinction;
23 for all have sinned and fall short of the glory of God,
24 being justified as a gift by His grace through the redemption which is in Christ Jesus;
25 whom God displayed publicly as a propitiation in His blood through faith. This was to demonstrate His righteousness, because in the forbearance of God He passed over the sins previously committed;
26 for the demonstration, I say, of His righteousness at the present time, so that He would be just and the justifier of the one who has faith in Jesus.
...and continuing in Romans 4:6-8...
6 just as David also speaks of the blessing on the man to whom God credits righteousness apart from works:
7 \"BLESSED ARE THOSE WHOSE LAWLESS DEEDS HAVE BEEN FORGIVEN,
AND WHOSE SINS HAVE BEEN COVERED.
8 \"BLESSED IS THE MAN WHOSE SIN THE LORD WILL NOT TAKE INTO ACCOUNT.\"
The simple and short of it is that God's promise is as good as the actual event.
Therefore God, who knew that Jesus Christ would take away all sins, could forbear and forgive sins before Christ (Romans 3:25).
And re-read Romans 3:22-24 - who and when is excluded by \"all\"?
No one and no time is/are excluded - the same promise and gift are to all, before and after Christ.
Which is why Paul can claim that Abraham is our father in faith in Jesus Christ - Abraham believed in, and is justified by \"Christ future\" just as surely as we today believe in, and are justified by \"Christ past\".
After all, if God is not constrained by time in forgiving our sins 2000 years after Christ's atonement, why would God be constrained by time in forgiving sin 2000 years before Christ's atonement (remembering again that God's promise is as good as the actual accomplished act)?