Answered by Shaykh Amjad Rasheed
Is it permissible to offer the funeral pray for a deceased in absentia (i.e. while his or her body is not physically present at the place of the funeral prayer)?
Yes, it is valid to offer the funeral prayer in absentia, but on condition that the one praying be absent from the town of the deceased. As for if they are in the same town, it is not permissible to offer the funeral prayer for him in absentia. However, if the deceased is in the same town as the one praying and it is difficult for him to attend the funeral prayer because of the likes of illness or imprisonment, Shaykh Ibn Hajar has conflicting opinions in the matter. In the Tuhfa, he sanctions the impermissibility of such a person offering the funeral prayer in absentia while in the Imdad, he sanctions its permissibility. The latter was sanctioned by Shams Al-Deen Al-Ramli in the Nihaya and there is leniency in it.
Condition: Obligation of Prayer
Another of its conditions is that the one offering the prayer must be of those for whom prayer is obligatory on the day of the deceased’s passing; i.e., he or she must be a Muslim, legally responsible , and pure  at the time. From this it is known that it is not permissible in our day to offer the funeral prayer in absentia for the Prophets, Companions and others for whom we were not obliged to pray on the day of their passing.
Proof from the Sunnah
The proof for the permissibility of praying for the deceased in absentia is indicated by what is in the two Saheehs  on the authority of Abu Hurayra (Allah be pleased with him), “that the Prophet (Allah bless him and grant him peace) announced the death of the Negus to his companions while in Madinah and he prayed for him and they prayed behind him.” Imam Nawawi says in the Majmu’, after mentioning the hadith, “it is rigorously authenticated and there is no refutation against it; they (i.e., those that differ) have no correct rebuttal to it.”
(Translated by Sidi Moustafa Elqabbany )
1. i.e., Sane and having passed puberty.
2. i.e., Free of menstruation and postpartum bleeding.
3. i.e., Saheeh Al-Bukhari and Saheeh Muslim.