Close relatives are more entitled than others, provided the deceased is of their own gender (that is, their own sex)
It is narrated from Aisha (may Allah be pleased with her) that the Messenger of Allah ﷺ said:
ليله أقربكم إن كان يعلم فإن كان لا يعلم فمن ترون عنده حظا من ورع وأمانة
“The one most entitled to wash the deceased is the closest of you to him, provided he knows (the correct method of doing it). But if he does not know, then whoever you think has some share of piety and trustworthiness (should wash him).”
Although this hadith cannot be used as evidence, it is correct that close relatives are more entitled, because they are more trustworthy in affection, compassion and keeping secrets, and give the matter their full attention. والله اعلم
In addition, being of the same gender is workable except in exceptional cases, as in the earlier hadith of Umm Atiyyah (may Allah be pleased with her), that the women washed the daughter of the Prophet ﷺ.
(Shawkani, may Allah have mercy on him) In the time of the Prophet ﷺ and the time of the Companions, men were washed by men and women were washed by women.
(Albani, may Allah have mercy on him) Except in exceptional cases, men should wash men and women should wash women.