The sin of pride. David wished to know how big and massive his kingdom was, to bask in the glory which was God’s and not his.
Also, the census was very feared at that time, as it allowed the govt to exercise massive control over the people, and could oppress them greatly.