Raised by the Temple priest, Joash was a good king to begin with:
2 Kings 12:2-3 All his life Joash did what was pleasing in the Lord’s sight because Jehoiada the priest instructed him. Yet even so, he did not destroy the pagan shrines, and the people still offered sacrifices and burned incense there.
But it lasted only as long as Jehoiada the priest (who installed him as king) was around to advise him:
2 Chronicles 24:17-18 But after Jehoiada’s death, the leaders of Judah came and bowed before King Joash and persuaded him to listen to their advice. They decided to abandon the Temple of the Lord, the God of their ancestors, and they worshiped Asherah poles and idols instead!
Jehoiada’s son, Zechariah, and other prophets relayed God’s view of this, but neither the people nor King Joash listened, instead:
2 Chronicles 24:21-22 Then the leaders plotted to kill Zechariah, and King Joash ordered that they stone him to death in the courtyard of the Lord’s Temple. That was how King Joash repaid Jehoiada for his loyalty—by killing his son. Zechariah’s last words as he died were, ‘May the Lord see what they are doing and avenge my death!’