David was punish.
2 Sam 12:9-12
9 Wherefore hast thou despised the commandment of the Lord, to do evil in his sight? thou hast killed Uriah the Hittite with the sword, and hast taken his wife to be thy wife, and hast slain him with the sword of the children of Ammon.
10 Now therefore the sword shall never depart from thine house; because thou hast despised me, and hast taken the wife of Uriah the Hittite to be thy wife.
11 Thus saith the Lord, Behold, I will raise up evil against thee out of thine own house, and I will take thy wives before thine eyes, and give them unto thy neighbour, and he shall lie with thy wives in the sight of this sun.
12 For thou didst it secretly: but I will do this thing before all Israel, and before the sun.
David's adultery with Bathsheba was a sin of passion, a sin of the moment that overtook him, but his sin of having Uriah killed was a premeditated crime that was deliberate and disgraceful. This may be why 1 Kings 15:5 emphasizes "the matter of Uriah the Hittite" and says nothing about Bathsheba. But the Lord judged both sins and David paid dearly for his lust and deceit
The sword did not depart from the king's household, and his wives were taken and violated just as he had taken Bathsheba. Indeed, David did pay four-fold, for Bathsheba's baby died, and his sons Amnon, Absalom, and Adonijah were slain (13:29; 18:14-15; 1 Kings 2:25). David's beautiful daughter Tamar was raped by her half brother (chap. 13), and David's concubines were humiliated publicly by Absalom when he captured the kingdom (16:22). For the rest of David's lifetime, he experienced one tragedy after another, either in his family or in the kingdom. What a price he paid for those few minutes of passion with his neighbor's wife!
The punishments God assigned to David were already stated in the covenant God had with Israel and which the king was expected to obey (Lev 26; Deut 27:1-30:20). If the nation rebelled against God, He would slay their sons in battle (Lev 26:17; Deut 28:25-26), take away their children (Lev 26:22; Deut 28:18), give their wives to others (Deut 28:30), and even take Israel out of its land into foreign exile (Deut 28:63-68). Because of Absalom's rebellion, David was forced to flee Jerusalem and live in the wilderness. But the covenant also included a section on repentance and pardon (Deut 30; Lev 26:40ff), and David took it seriously.