Chapters 18-20 tell of some of David鈥檚 military victories. In chapter 21, we are told of what seems like a strange failure on David鈥檚 part. David conducts a census. God sees this as rebellion because David is depending on how many soldiers he has rather than on God. God鈥檚 punishment extends to all of Israel and is stopped by David sacrificing offerings on an altar. The location of that altar will eventually become the location of the Temple.
When we think of sin we think of the adultery David committed. We don鈥檛 always think of depending on things other than God. For David it was military might. For us it could be our investments, possessions, our nation鈥檚 military or the doctors we see. It鈥檚 good to make plans to take care of ourselves, but ultimately, our dependence is on God.