I’ve read many commentaries on 2 Samuel 24:3 that debate several reasons why the census was sinful but none of them address Joab’s reason for asking. Joab was a gifted military commander and loyal to David, but he was not a moral man. He killed Abner, Uriah, and Amasa, none of them for military advance but for various and questionable reasons. His concerns seem directed toward military or personal gain, and I see nothing to indicate humility. With no indication of him acknowledging God for much of anything, why would he now be concerned about offending God. My question is not, what was the offense, but what would generate Joab’s concern. Once that question is satisfied, the context of the verse might become clear.
Joab believed in God's power. He was not an idol worshiper.
2 Samuel 2:27 Joab answered, "As surely as God lives, if you had not spoken, the men would have continued pursuing them until morning."
2 Samuel 10:11 Joab said, “If the Arameans are too strong for me, then you are to come to my rescue; but if the Ammonites are too strong for you, then I will come to rescue you. 12Be strong, and let us fight bravely for our people and the cities of our God. The Lord will do what is good in his sight.”
Uriah respected him.
2 Samuel 11:11 Uriah said to David, "The ark and Israel and Judah are staying in tents, and my commander Joab and my lord's men are camped in the open country. How could I go to my house to eat and drink and make love to my wife? As surely as you live, I will not do such a thing!"
Joab is a complex character.