The position of Agreement (ijmā‘) is that it is necessary (wājib) to appoint an Imam. The difference of opinion is on the question whether [the appointment] must be by Allah  or by His servants, and whether the basis [for appointment] is textual evidence (dalīl sam‘ī) or reason (dalīl ‘aqlī) . The correct position is that the servants must appoint a Caliph on the basis of textual evidence because of the statement of the Prophet (ﷺ), “Whoever dies not having known the Imam of his time, dies the death of the days of Ignorance (al-jāhilīyyah) .” [Musnad Ahmad, IV, 96]
And they must appoint someone, since the people at the time of the Prophet’s (ﷺ) death made this question the most important matter of consideration, so important in fact that they considered it more important than the matter of his burial , and so also has it been after the death of each Imam. And they must appoint someone for so many legal obligations are dependent on the Imam, as he (al-Nasafi) has indicated in this statement:
“The Muslims must have an Imam, who will carry out the administration of their decisions, the maintaining of their restrictive ordinances (ḥudūd), the guarding of their frontiers , the equipping of their armies, the receiving of their zakat, the punsihment of those who rebel and those who spy and highwaymen, the establishment of jumu‘ah and ‘Eid, the settlement of disputes which take place among the servants (of Allah), the acceptance of the testimony of witnesses in matters of legal rights, the giving in marriage of the young men and women who have no guardians, and the distribution of the war booty” [Taftāzānī adds:] and similar matters which other individuals from the Ummah are not allowed to be in charge of.
(Excerpted from Sharḥ al-‘Aqā’id al-Nasafīyyah [Taftāzānī ‘s commentary of al-Nasafī’s essay on belief])
*Sa‘d al-Din Mas‘ūd ibn ‘Umar ibn ‘AbdAllah al-Taftāzānī [722H/1322 CE – 793H/1390 CE] was a renowned scholar and polymath from a distinguished scholarly family, born in the village of Taftazan in Khurasan. He authored works on Arabic grammar, rhetoric, theology, logic, jurisprudence (fiqh) and Quranic exegesis (tafsīr). His commentaries on well-known works in various fields of Islamic sciences were widely used in madrassas around the world until modern times. Imām Ibn Ḥajar al-‘Asqalānī famously remarked that ‘science ended with him in the East’ and ‘no one could ever replace him’ (al-Durar al-Kamina).
**Najm al-Dīn Abu Ḥafṣ ‘Umar b. Muḥammad b. Aḥmad al-Nasafī, a master of the Hanafi school of law who excelled in many sciences and authored over a hundred books. He was the teacher of Marghināni (author of al-Hidāya), who stated, “I heard Najm al-Dīn (i.e. al-Nasafī) say, ‘I narrate hadiths from 550 Shaykhs’. He passed away in the year 537H (1142 CE).
 The Shī‘ah have the view that Allah appoints the Imam. But Ahl al-Sunnah insist he must be appointed by the people through a pledge of allegiance (bay‘ah).
 Most of the Mu‘tazilah (a misguided sect influenced by Greek Philosophy) held the view that the proof for this obligation was rational, not textual.
 Commenting on the following hadith narrated by Ibn ‘Abbas (r): “Whoever disapproves of something done by his Amīr (ruler) then he should be patient, for whoever disobeys (disunites and goes away from) his Sultan even for a span will die as those who died in the pre-Islamic period of Ignorance” Imām Ibn Ḥajar al-‘Asqalānī explains the meaning of the phrase مات ميتة جاهلية:
“To die as those who died in the pre-Islamic period of Ignorance (al-jāhilīyyah) means the state of death: to die in a state of misguidance with no Imam to obey, as the inhabitants of that era had no such kind of ruling. The hadith doesn’t mean that the Muslim will die as a kāfir but as a disobeying Muslim. This Hadith has possible definitions: To resemble between the state of death between the disobeying Muslim and the Jāhil, even if the Muslim was not in reality a Jāhil; or, to frighten and reprimand, and this meaning is not the apparent one… Ibn Baṭṭāl said: this hadith is an argument to not disobey the Sultan even if he is wronged. The scholars agreed unanimously on the obligation of obeying the empowered Sultan and (engaging in) jihad under his commandment. As well the scholars consider that obeying the Sultan is better than disobeying him as this act prevents bloodshed and mitigates the masses.” (Fatḥ al-Bārī Sharḥ Ṣaḥīḥ al-Bukhārī #7053)
 Ibn Kathīr said, “What is famously related from the majority of scholars is that the Prophet (ﷺ) died on Monday and was buried on Tuesday night.” (al-Bidāyah wa al-Nihāyah (5/237) and Ṣaḥīḥ al-Sīrah al-Nabawīyyah, p.728)
 The Prophet (ﷺ) said: “The Imam is but a shield for them (the Muslims). They fight behind him and are protected by him (from aggressors)…” (Ṣaḥīḥ Muslim on the authority of Abu Hurayrah (r))