"In order to test him..." - Those are the words in 2 Chronicles (32:31) that describe what God allowed to occur as recorded in Isaiah 39 with Babylon and Hezekiah. After being healed, “his heart was lifted up” (2 Chron 32:25), Hezekiah, dazzled by the envoy from Babylon, showed them his own treasures, all of them (Isaiah 39:1-2), indicating his intention to impress and align with Babylon at all costs. Here was the opportunity to give glory to God, but all Hezekiah revealed was his worldly riches. There is similarity to the self-glorying declarations of Moses at the rock in the wilderness (Num 20:2-13) which also ended with consequences from the Lord. Isaiah shows up unbidden (v3) as the Word of God often does to confront us. God’s questions are like those to Adam and Eve (“where are you…what did these men see...where are they from”), questions that we know God already knows the answers to, but which indicate his judgment. Hezekiah tells the truth (either in repentance or brazenly, we are not sure – v4) and then Isaiah replies with deadly calm that one day all those treasures would belong to Babylon (vv5-6), and that Hezekiah’s descendants would become eunuchs serving in the courts of Babylon (v7).
Hezekiah’s answer in v8 leaves us all scratching our heads (v8); he doesn’t seem to care (at that moment) about the future of the country he leads.