All perfect praise be to Allah the Lord of the Worlds. May Allah`s peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
The Hadith intended in the above question is the one reported by Bukhari in his Sahih (Hadith No.1342): Narrated Anas: "We were in the funeral procession of the daughter of Allah's Messenger (Peace and blessings be upon him), and Allah's Messenger (Peace and blessings be upon him) was sitting near the grave and I saw his eyes full of tears. He said: "Is there anyone amongst you who did not have sexual relations with his wife last night?" Abu Talha replied in the affirmative. And so Allah's Apostle told him to get down in her grave and he got down in her grave and buried her." The woman mentioned in this Hadith is Um Kulthum; the wife of Othman Bin Affan (May Allah be pleased with them). This Hadith was also mentioned by Ibn Hajar in {Fateh Al-Bari, vol.3/pp.158}.
Based on this Hadith, scholars have concluded that when non-Maharam men are equal in terms of the attributes that entitle them to bury the deceased; namely, age, righteousness, and knowledge of the rulings of Sharia, preference is granted to the one who didn`t have sexual relations with his wife in a long time.
Ibn Hajar (May Allah have mercy on him) said: "Based on this Hadith, when non-Mahrams are equal in these attributes, preference is granted to the one who didn`t have sexual relations with his wife in a long time." {Tohfat Al-Mohtaj, vol.3/pp.170}.
The wisdom behind this is that such a person isn`t likely to be reminded by the devil of that intimate night as such memories don`t fit this great loss.
However, jurists (May Allah have mercy on them) said: "The husband is the most entitled to bury his wife, and they wondered why the Prophet (Peace and blessings be upon him) preferred Abu Talaha, although a non-Mahram of the deceased woman-Um Kulthum-over her husband Othamn Bin Affan. They tried to provide an answer for this as follows:
First: Ibn Hajar (May Allah have mercy on him) said: "It is possible that Othman was in a state of shock and extreme sorrow for losing his wife and the Prophet (Peace and blessings be upon him) feared that he may not be able to adhere to the rules of Islamic burial. Or, the Prophet felt that Othaman wasn`t in a state that enables him to bury her; therefore, he preferred Abu Talha and chose him in specific because he didn`t have sexual relations with his wife (Abu Talha`s) the night before." {Tohfat al-Mohtaj, vol.3/pp.169}.
Second: It could be that none of the deceased`s Mahrams was there at the time of the burial; not even her husband Othman Bin Affan, because they were occupied with a greater matter, and this was mentioned by At-Tahawi in his book {Bayaan Moshkil Al-Athar}.
Third: It was said that the Prophet (Peace and blessings be upon him) wanted to mildly show Othaman that he (Peace and blessings be upon him) was displeased with Othman`s being busy having sex with his slave women and not paying attention to his sick wife. Ibn Hajar said: "Ibn Habib reported that preference of Abu Talaha over Othman was that because Othamn had sexual relations with some of his slave women the night his wife died, so the Prophet (Peace and blessings be upon him) wanted to implicitly stop him from entering the grave of his wife." However, Othman is excused for the fact that his wife`s sickness has lasted for a long time, and he didn`t know that she would die that night. And Allah The Almighty Knows Best.
[1] A person with whom marriage is generally permissible.
{2} An unmarriageable person with whom marriage is totally unlawful