And they abandoned the house of the LORD, the God of their fathers, and served the Asherim and the idols. And wrath came upon Judah and Jerusalem for this guilt of theirs.
2 Chronicles 24:18
It is sad to watch a good man go bad. That is exactly what happened with Joash. As long as his mentor, Jehoida the priest was alive, king Joash faithfully followed the Lord. In fact, he was so concerned for the glory of God that he spent decades of time and oodles of cash to restore God's temple in Jerusalem.
But after Jehoida's death, Joash was easily influenced by the royal family and other idolatrous elements in Jerusalem. And the result was a very quick return of Judah to idolatry. It may have began with tolerance, but it ended with Joash himself killing the son of Jehoida when God gave the priest's son a prophecy against the king. The young king who had been so faithfully concerned about the Word of god and following it became a tyrant bent on wiping out the very message that God directly gave to him.
God's judgment on Judah was swift. A small force of Syrians came against Jerusalem. Judah should have easily wiped them out, but God let them prevail and ransack the city. Joash himself was wounded in the fight. By the time the Syrians return to Damascus with Judah's spoils, Joash is wounded and bed-ridden in the palace.
At that moment other elements of the royal line (probably his own sons) conspire against him and kill him in his weakness. God's judgment brought an end to Joash's own rebellion before it could worsen. The consequences of his cavalier disregard for God's Word were severe and serious. And they came swiftly!