Answer
In the Name of Allah, Most Gracious, Most Merciful.
All praise and thanks are due to Allah, and peace and blessings be upon His Messenger.
In this fatwa:
Some scholars said the most appropriate person to lead the funera; prayer is the legal guardian of the deceased, then the (Muslim) ruler, then the father of the deceased, grandfather, or great grandfather, then the son or the grandson, then the one closest in relationship.
In his famous work, Fiqh As-Sunnah, Sheikh Sayyid Sabiq, elaborates on the subject as follows:
Jurists differ as to the most worthy person to lead a funeral prayer. Some said the most appropriate person is the legal guardian of the deceased, then the (Muslim) ruler, then the father of the deceased, grandfather, or great grandfather, then the son or the grandson, then the one closest in relationship. This is the opinion of the Maliki and Hanbali schools.
Others other scholars said the best person is the father, then the grandfather, then the son, then the grandson, then the brother, then the nephew, then the paternal uncle, and then his son in accordance with their blood ties with the deceased. This is the opinion of Ash-Shafi`i and Abu Yusuf.
Abu Hanifah and Muhammad ibn Al-Hasan, however, are of the opinion that the preferred order is the (Muslim) ruler if present at the funeral, then the judge, then the imam of the locality, then the guardian of a deceased woman, then the nearest blood relative. Of the blood relatives, if both father and his son are present, the father should be given precedence.
Read also:
Is Offering Prayer at Graveyards Permissible?
What Are the Funeral Rituals for a Dead Child?
Can You Offer Funeral Prayer on an Anonymous Woman?
Did Women Participate in the Funeral Prayer for the Prophet?
Is a Large Gathering at Someone’s Funeral Prayer a Sign of His Piety?
Is Wife Allowed to See Deceased Husband Before Burial?
Can a Woman Go to a Funeral in Islam?
Can You Attend Funeral of Non-Muslim Relatives?
Can You Pray Janazah at the Cemetery?
Almighty Allah knows best.