The tragic end of Ahaziah was not the result of a random sequence of events or bad timing. Instead, his downfall was a deliberate act of divine providence that guided him to his death at the exact moment of Jehu's rebellion.
The primary approach among commentators is that Ahaziah's decision to visit Joram was a direct punishment orchestrated by God. It was God who planted the desire in Ahaziah's heart to make this journey, ensuring that he would be present to fall alongside Joram [מצודת דוד, רד״ק]. Ahaziah shared in the harsh fate of the house of Ahab because his own mother was a member of that family [מלבי״ם]. At the same time, Jehu was acting under the power of prophecy. He viewed it as his absolute duty to wipe out the house of Ahab completely, leaving no survivors behind [ביאור שטיינזלץ].
The nature of this complete defeat is understood in a few different ways. The primary approach views it as a physical downfall [ביאור שטיינזלץ], specifically in the sense of being trampled, crushed, and destroyed [מצודת ציון, רלב״ג]. Others explain it as a state of deep confusion and panic that God cast upon Ahaziah, which is exactly what drove him to seek out Joram in the first place [רד״ק]. A final perspective paints a graphic picture of ruin, describing it as a state of being mixed with dirt, like a person rolling and becoming stained in his own blood [רש״י, רלב״ג].