Seems pretty logical to take a census. So it sounds odd to us that it was a sin. But to understand why, we have to look at the history of the Hebrews.
God had made a covenant with them that if they remained faithful, they would be taken care of. A covenant is far more than a contract. It is a relationship based on love and trust. They were to be God's people and would have no need to fear that God would abandon them nor that their enemies would destroy them.
So what did David do in this instance? By making sure he had enough men to wage battle, he was preparing for war. He was taking care of himself and his territory rather than trusting in God. In other words, he was placing his trust in himself and in his men. So, he was breaking the covenant with God, breaking his relationship with God which he realized and recognized as sinful.
God gave David a choice of one of three evils to befall his people. For the Hebrews, God was the cause of both good and evil. Evil things happened because of God's displeasure with the wrongdoer. Later, the theology of the Hebrews attributed evil to Satan, for example, 1 Chronicles 21:1.
The evils from which he was to choose were: three years of famine or three days of pestilence in the land or three months of pursuit by his foes. David chose to place himself in the hands of God rather than in the hands of his enemies for he knew that God is merciful. Therefore, he doesn't choose the last one. God sends a pestilence and after many deaths, David begs God to withhold the punishment against the people for they have done nothing wrong. He is willing to accept the punishment for himself.
In the subsequent text which wasn't in the day's reading, as Jerusalem is about to be destroyed, God stops the destroying angel. In verse 16, God relents because of a special affection for Jerusalem.
In verse 17, it seems that this happens because of David's repentance. But verses 18-25 describe the purchase of the area and show David offering sacrifices there. Therefore, the reason God stops the destruction of Jerusalem is because this spot is to become the location of the Temple.
David's sin was failing to live by the covenant with God, failing to trust in God rather than in human means to save his people and his territory from his enemies.
The point for us to remember is that this Scripture text is about us and not just about David. All of us need to look into our lives and see in what or whom we place our trust.
Is it in money and possessions, our jobs, our recreational pastimes, other people?
Where does God come in our list of priorities?
First, second or dead last?