المرء مع من احب
A person will be with whom he loves. (Bukhari, Muslim)
Mulla Ali Qari (RH) states that the most common understanding for this hadith is that when a man loves those who are good and pious he will be raised with them on the day of resurrection, and if he loves those who are evil and corrupt he will be raised with these people on the day of resurrection.
This can be further seen in the hadith:
المرء على دين خليله
A person is upon the religion of his friend. (Tirmidhi)
It is narrated in Bukhari, on the authority of a large number of sahaba’s that a man came up to the Prophet Muhammad (sallalahu alayhi wassalam) and asked
“What do you say of a man who loves a certain group of people but cannot be of them?”
To this Muhammad (sallalahu alayhi wassalam) replied;
“A person will be with whom he loves”
“There was nothing which made us (sahaba’s) happier in this world than to hear this” (Muslim)
As they loved Muhammad (saw) greatly, this hadith indicated that they would be with him the hereafter.
Some scholars have stated that this is a glad tiding of a good death for those who love the pious as they will be raised amongst them on the day of resurrection.
May Allah make us from those who are resurrected with the pious on the day of reckoning. Ameen.