Like father like son: Ahaziah followed his father Ahab's footstep. And like his father Ahab, he came under divine judgement and died of his injury sustained from a fall.
But Ahaziah was given two opportunities to repent, but he didn't. Firstly, Elijah intercepted his messengers who were on the way to consult Baalzebub, the god of the Ekron. Elijah delivered God's judgment that Ahaziah would not leave his bed and would die on his bed. Secondly, Elijah met him face to face and declare the same message. But there was no indication that Ahaziah humbled himself like his father Ahab did. So, he died according to the prophecy given to him.
Prophetic declaration of God's intention is not irreversible. God is known to relent from what He has planned to do when confronted with genuine repentance and humility. He relented when Ahab humbled himself. He relented too when the king of Nineveh humbled himself at Jonah's preaching: "When God saw what they did and how they turned from their evil ways, he had compassion and did not bring upon them the destruction he had threatened" (Jonah 3:10).
If we repent, God will relent. That is grace. Law punishes, but grace forgives. But it is conditional on our act of confession of our sins (admitting we are wrong and turning away from our sins): "If we confess our sins, God is faithful and just and will forgive us and purify us from all unrighteousness" (1 John 1:9). The God of the NT is also the God of the OT -- He has not changed.
Father, thank You that You are always faithful to forgive whenever we confess and acknowledge we have sinned against You. You did it for Christ's sake for Christ's death has paved the way for Your grace to be made effective in everyone who repents. Amen.