When Athaliah, Ahaziah's mother, learned of her son's death, she immediately destroyed the entire royal family.
References for 2 Kings 11:1
But Jehosheba, King Jehoram's daughter and Ahaziah's sister, secretly took Ahaziah's son Jehoash from the rest of the royal children who were about to be murdered and hid him in a bedroom along with his nurse. In this way Jehoash was hidden from Athaliah and wasn't murdered.
References for 2 Kings 11:2
He remained hidden with his nurse in the LORD's temple for six years while Athaliah ruled the country.