There was a covenant between God and David that stated that only a descendant of David would sit on the throne in Jerusalem. Yet Queen Athaliah, the daughter of Jezebel, occupied the throne for six years. How is that explained?
The promise and prophecy to David (e.g. Shmuel II, ch. 7) is that his dynasty will not lose the kingship forever (!), but there obviously were periods, like during the 2,000 year long exile until today, where it will be temporarily lost. Similarly, the prophet Achiya was commanded by God Himself to anoint Y’rav’am, despite not being from David’s tribe of Yehuda, to be king temporarily, but not forever (M’lachim I 11, 39). The day will come when the kingdom will once again (!) return to David’s family, in the times of Mashiach ben David.