The story is about a census David makes of Israel. For whatever reason, this census angers YHWH bringing a plague upon Israel. It's not clear why taking a census is so bad. The speculation is that in taking a census David is expressing proprietorship over the people, treating Israel as his property. That's a usurpation of YHWH's position as the true king of Israel.
All that is interesting in its own right, but the real puzzles are what I'm about to point out.
The first puzzle is why David undertakes the census in the first place, given YHWH's disapproval. Here's what we read in 2 Samuel:
2 Samuel 24.1That's curious, no? The anger of the Lord burned against Israel, so he incited David against them by asking David to undertake a census. You'd think YHWH could just act directly against Israel without any excuse or provocation. But YHWH commands David to take a census which YHWH will find offensive and, thus, unleash the plague on Israel.
Again the anger of the Lord burned against Israel, and he incited David against them, saying, “Go and take a census of Israel and Judah.”
All that is very, very weird. But it's not really a contradiction. The contradiction comes when we compare this narrative with a retelling of the same story--David taking the census and the subsequent plague--in 1 Chronicles:
1 Chronicles 21.1See the problem? In 2 Samuel "the Lord" incites David to take the census. In 1 Chronicles it's "Satan."
Satan rose up against Israel and incited David to take a census of Israel.
What's going on? Two things might be going on. First, we know that 1 Chronicles is the later document. So, first hypothesis, is that the author of 1 Chronicles is trying to clean up the weirdness of the earlier story. Why would God incite David to do something God would find offensive? By plugging in Satan some of that weirdness goes away.
A second hypothesis is that the author of 1 Chronicles is writing a historical apology for the Davidic dynasty. Consequently, the bias of the author of 1 Chronicles is to portray David in the best light possible. For example, David's sin with Bathsheba isn't recounted in 1 Chronicles. So the theory is that the introduction of Satan in 1 Chronicles 21 is a way to lessen David's culpability in the episode. The devil made him do it.
Then why not eliminate the story like what was done with Bathsheba? Because the story of the census explains why the temple was built at the threshing floor of Araunah the Jebusite. (David turns back the destroying angel by offering a sacrifice at the threshing floor of Araunah.) Beyond defending the Davidic dynasty the author of 1 Chronicles is also keen to defend Jerusalem and the temple cult as the cornerstone of Israel's religious identity. Consequently, the story about the origins of the temple has to be included.
So those are two ideas about why "the Lord" in 2 Samuel 24 becomes "Satan" in 1 Chronicles 21.
Regardless, I bring up the issue simply to say that if you believe in "biblical inerrancy" you're going to have to struggle with 2 Samuel 24.1 and 1 Chronicles 21.1.