I'll repeat, "David didn't commit adultery according to the law of the land in his day."
God's very first instruction to Adam was to be fruitful and increase. A king could afford to have more than one wife in David's day and time.
David was not the first or only man to have more than one wife and Bathsheba's husband was dead. She was not married. Neither David nor Bathsheba committed adultery according to the law at that time.
A man could have more than one wife but a woman could only have one husband at a time.
In the NT a man could not serve in an ordained office if he had more than one wife.
Times change.
I think David did commit adultery, he was sleeping with Bathsheba whilst uriah was still alive. What is that if it's not adultery? And not only did he commit adultery, but after doing it, he then contrived to get her husband killed my putting him at the front of the battle when he was weak. Uriah's heart was right before God and he was loyal to David yet he was treated so badly.
God did forgive Davids sins when he repented, but he did still suffer terribly for committing those sins, including losing his first born son!
2 Samuel 12
And Nathan said to David, Thou art the man. Thus saith the LORD God of Israel, I anointed thee king over Israel, and I delivered thee out of the hand of Saul; And I gave thee thy master's house, and thy master's wives into thy bosom, and gave thee the house of Israel and of Judah; and if that had been too little, I would moreover have given unto thee such and such things. 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. 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. 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. For thou didst it secretly: but I will do this thing before all Israel, and before the sun.
And David said unto Nathan, I have sinned against the LORD. And Nathan said unto David, The LORD also hath put away thy sin; thou shalt not die. Howbeit, because by this deed thou hast given great occasion to the enemies of the LORD to blaspheme, the child also that is born unto thee shall surely die.
David was the king, he had a responsibly to show the right way to live before others. And God's people have that responsibility too. We have to live right before God and others, and follow Jesus showing the right example. The stronger we are in God, the more we know and the more responsibility we have.
Once we know the truth and we know God, and when we carry on sinning wilfully, God will punish us because we're not ignorant and we know right from wrong.