In 2 Chronicles 2:17 we are told "Solomon took a census of all the foreigners residing in Israel, after the census his father David had taken; and they were found to be 153,600." Why was God not angry about this Census, yet furious with David for taking a Census?
Maybe it was because Solomon took a census of all the foreigners, while David numbered the children of Israel without making this offering:
And the LORD spake unto Moses, saying, When thou takest the sum of the children of Israel after their number, then shall they give every man a ransom for his soul unto the LORD, when thou numberest them; that there be no plague among them, when thou numberest them. This they shall give, every one that passeth among them that are numbered, half a shekel after the shekel of the sanctuary: (a shekel is twenty gerahs:) an half shekel shall be the offering of the LORD. Every one that passeth among them that are numbered, from twenty years old and above, shall give an offering unto the LORD. The rich shall not give more, and the poor shall not give less than half a shekel, when they give an offering unto the LORD, to make an atonement for your souls. [Exodus 30:11-15 KJV]
God wanted the children of Israel numbered only so that they would know how much to give to the Lord. David just wanted to know, with Satan's influence, how big his army was; he was putting his trust in his military might rather than in the promises of God.
A word of caution needed here for the speculations made by me here. I have not spent a large amount of time meditating on these scriptures and opinions are based on my limit experience with what I have studied in the Bible.
The Bible does not explicitly state why Solomon's census was good or bad but because there is no text concerning God's disappointment you could conclude that it was good. When David conducted the census in 1 Chronicles 21:1-16, the Bible does not spell out what exactly caused God to be displeased with David's census other than Satan rose up against Israel that caused David to conduct a census. Some sin was occurring and it could have been anything from building an army instead of trusting God to just wanting more money from taxes.
In Solomon's case and from the text in 2 Chronicles 2:17 - 3:1, the census was to aid in determining the types of jobs people would need to be assigned to build the 'house of the Lord' / temple for the name of the Lord.
Conclusion: Solomon's motives for taking a census was for good or righteous reasons but in David's case, it was because of Satan.
Your brother in Christ.