While Joab was out fighting the Ammonites, David was dawdling around back in Jerusalem. One day he looked out his window and, on the roof next door, he saw a beautiful naked woman who happened to be bathing to clean herself after her period. David watched her bathe with lust in his heart.
Later, he made some inquiries and learned she must have been Bathsheba, wife of Uriah the Hittite, one of his loyal soldiers. But David was not used to having his desires unfulfilled, so he ordered Bathsheba brought to him and raped her (as she had no ability to consent) then sent her back home.
A few weeks later, Bathsheba sent word to David that she was pregnant. David did not survive survive all those years as an outlaw for nothing–he immediately sent to the front to have Uriah sent back to Jerusalem to report on the state of the war.
After Uriah gave his report, David was all, Great news, great news! You’re a loyal soldier, Uriah. Now go home and spend some time with that pretty wife of yours!
But Uriah didn’t go home. Instead he camped in the king’s courtyard.
David was vexed when he was told Uriah never went home. At breakfast he was all, Hey, Uriah, why didn’t you go home last night? Uriah was all, How can I sleep in a bed of pillows while my fellow soldiers shiver in tents? Nay, I shall not sleep in my own bed until the war be over! David grunted. He was all, I want you to stay another day to rest before you head back to the front.
That night, David got Uriah drunk, in the hopes that he’d forget his vow and go home. Alas for Uriah, however, he chose to pass out on David’s couch.
When David saw him in the morning, he sighed and retired to write a letter to Joab, instructing him to put Uriah on the front lines and make sure to draw the other men back so Uriah would be killed. Then he sealed the letter and gave it to Uriah to deliver to Joab.
So Joab did as he was commanded and sent a messenger to David with the news. David again sighed and sent a message back to Joab, instructing him not to fret over or mourn for Uriah, for the sword devours all, and to keep on fighting.
David let Bathsheba mourn for the required time, and then brought her into the harem and married her to legitimize his soon-to-be-born son.
But God saw all and was angry.