From what I learned in Islamic schools for many years, a leader in Islam should be selected based on the shura system and Majlis ash-Shura. The shura system means Islamic scholars hold meetings and discuss among them to determine the best leaders who are eligible to lead the country.
In other words, it is not an election or a monarchy as practiced by Muslim countries today. The weakness of the election-based system, is if the majority voters are unwise, they will vote for unwise leaders.
In the past, after the death of Prophet Muhammad (Peace Upon Him), Rashidun Caliphates were chosen based on the shura system where the companion of prophet Muhammad (sahabat) hold meetings to determine who qualify to become the leader. It started with Saidina Abu Bakar as-Sidiq.
In the days of the Kingdom of Abasiyah, Islamic leaders were selected based on the system of descendants. But it was not the same as today, because those who deserve to be the caliphate at that time had been evaluated and considered as qualified by the Islamic scholars. In other words, they are not chosen solely because of their decendants.
Traditional Sunni Islamic lawyers agree that shura, translated as 'consultation of the people', is a function of the caliphate. The Majlis ash-Shura advise the caliph. The importance of this is premised by the following verses of the Quran.
Surah Ash-Shuraa, verse 38 (42.38): View this verse + translation on the legacy.Quran website here
Translation: "And those who have responded to their Lord and established prayer and whose affair is [determined by] consultation among themselves, and from what We have provided them, they spend."
Surah Ali-Imran, verse 159 (3.159): View this verse + translation on the legacy.Quran website here.
Translation: "So by mercy from Allah , [O Muhammad], you were lenient with them. And if you had been rude [in speech] and harsh in heart, they would have disbanded from about you. So pardon them and ask forgiveness for them and consult them in the matter. And when you have decided, then rely upon Allah . Indeed, Allah loves those who rely [upon Him]."
More details here on Wikipedia:
Political Aspects Of Islam - Majlis Ash-Shura - Wikipedia
More interpretations of the verses I mentioned earlier from Tafsir Maarif-Ul-Quran:
Surah Ali-Imran, verse 15: More interpretations here in English.
Surah Ash-Shuraa, verse 38: More interpretations here in English.