Please compare 2 Samuel 24:1 with 1 Chronicles 21:1 to see the discrepancy.

2 Samuel 24:1, “And again the anger of the LORD was kindled against Israel, and he moved David against them to say, Go, number Israel and Judah.”

1 Chronicles 21:1,2: “And Satan stood up against Israel, and moved David to number Israel. And David said to Joab and to the princes of the people: Go, number Israel from Beersheba even to Dan; and bring me word, that I may know the sum of them.

In the margin of the King James Version, it shows “Satan” where it says “he” in the 2 Samuel scripture. As your question intimates, it seems out of character for God to incite David to sin, then punish the people of Israel. The account in 1 Chronicles makes more sense that it would be Satan to tempt David to sin, so we believe that this account is the more accurate. 

Additional Resources: 
(Online Article) “Numbering the People,” Herald Magazine
Related FAQ: “2 Samuel 24: Why was it wrong for David to take a census?”