Praise be to Allah.
The one who is most entitled to lead the funeral prayer over the deceased is the imam of the mosque, whether or not the deceased left instructions that a particular person lead the funeral prayer over him. If the imam of the mosque gives up that right and allows the one whom the deceased had named to lead the prayer, there is nothing wrong with that. But if he holds onto his right, then he has the right to do so, because of the hadeeth of Abu Mas‘ood al-Ansaari (may Allah be pleased with him), in which it says: “…No man should lead another man in prayer in his place of authority, or sit in his place of honour in his house, without his permission.”
It was narrated that Saalim ibn Abi Hafsah said: I heard Abu Haazim say: I was present on the day al-Hasan ibn ‘Ali died, and I saw al-Husayn ibn ‘Ali poking Sa‘eed ibn al-‘Aas in the shoulder and saying: Go forward (to lead the prayer); were it not that it is Sunnah, you would not be asked to go forward.”
Saalim is da‘eef (i.e., a weak narrator), but a similar report was narrated by an-Nasaa’i and Ibn Maajah with another isnaad from Abu Haazim. Ibn al-Mundhir said in al-Awsat: There is no hadeeth of a higher category concerning this matter apart from this, because the funeral of al-Hasan was attended by a large number of the Sahaabah and others.
End quote from Talkhees al-Habeer, 2/88 by al-Haafiz Ibn Hajar (may Allah have mercy on him).
It says in Fath al-Qadeer (2/117): The one who is most entitled to lead the funeral prayer for the deceased is the ruler, if he is present, because giving anyone else precedence over him is a kind of disrespect towards him. If he is not present, then the qaadi (judge) should lead the prayer, because he is in a position of authority. If he is not present then the imam of the neighbourhood should lead the prayer, because the deceased accepted him (as imam) when he was alive. Next in order of preference comes the next of kin… End quote.
Shaykh Ibn Baaz (may Allah have mercy on him) was asked:
If the deceased had left instructions that a particular person should offer the funeral prayer for him, does this person take precedence over the regular imam?
He replied: The regular imam is more entitled to offer the funeral prayer than the one whom the deceased had requested, because the Prophet (blessings and peace of Allah be upon him) said: “No man should lead another man in prayer in his place of authority”, and the imam of the mosque is the person of authority in his mosque.
End quote from Majmoo‘ al-Fataawa, 13/137
And Allah knows best.