See also 2 Samuel 12:9, 10-14, 11, 14, 15.
2 Samuel 11:1 - 27
ESV - 1 In the spring of the year, the time when kings go out to battle, David sent Joab, and his servants with him, and all Israel. And they ravaged the Ammonites and besieged Rabbah. But David remained at Jerusalem. 2 It happened, late one afternoon, when David arose from his couch and was walking on the roof of the king's house, that he saw from the roof a woman bathing; and the woman was very beautiful.
For follow-up discussion and general commentary on the topic. Comments are sorted chronologically.