In the story of David's life, God is the man in his corner—the Paulie to his Rocky, massaging his shoulders and providing encouraging tough-talk. It would be fair to say that, in these stories, God gets pretty political—he's championing his favorite candidate for power, David, over any and all comers.
Even if a charismatic guy like David's son, Absalom, provides a somewhat reasonable and well-grounded challenge to David's power—guess who's gonna come out on top? David.
God can't get enough of this guy.
In fact, as the writer Jack Miles points out, God refers to himself as a father for the first time in 2 Samuel, prompted by the great moment where David brings the Ark into Jerusalem and then dances ecstatically before it. God says that he will act as a father to David's offspring, though it implies he'll act as David's father in the present: "I will be a father to him, and he shall be a son to me. When he commits iniquity, I will punish him with a rod such as mortals use, with blows inflicted by human beings." (2 Sam 7:13-14)
Yet God does more than just lead cheers for David, thrusting pom-poms into the sky on the sidelines as David defeats enemy after enemy. He chastises David when he goes wrong—punishing him for murder and adultery by causing his first child with Bathsheba to die after birth. At the same time, God honestly loves David—he's just trying to correct his course of action and lead him on the right path.
But it's debatable whether God loves anyone else in the Second Book of Samuel. There are tons of people who simply inherit tragedy from their forefathers (like the seven sons of Saul who are executed by David to atone for their father's sins), without any forgiveness or intervention on God's part. David is the center of attention—and insofar as other people fail to align themselves with that center of attention, their lives end up being pretty disposable.
There's an even more baffling—even, perhaps, sinister—side to God's character in 2 Samuel. For example, in the final chapter, God provokes David to violate the law and conduct a census. God then punishes Israel with a pestilence that kills tens of thousands of people… for something David alone decided to do (although David doesn't personally get punished), and which God inspired him to do in the first place. It's confusing behavior to be sure—beyond the understanding of human beings, at least.
A bigger question is, "Why does God love David?" It's a tough question to answer. David is totally talented—he's a musician, a poignant poet, a great leader. But sometimes it seems almost like God's blessing is what makes David such hot stuff in the first place. God's decision-making is as inscrutable and hard to discern as… well, that of some human beings. Like the God who says "I am what I am" to Moses in Exodus, the God of 2 Samuel is, indeed, a puzzle.