Fiqh-us-Sunnah Volume 4, Funerals and Dhikr, Fiqh 4.053A.
Section : Funeral Prayer in the Graveyard.
A majority of jurists disapprove of offering funeral prayer in a graveyard. This is the view of ‘Ali, Abd-Allah ibn ‘Amr, and Ibn ‘Abbas, and also of ‘Ata, An-Nakh’i, Ash-Shafi’i, Ishaq, and Ibn Al- Munzhir, and they cite the Prophet’s hadith: “The entire earth is a mosque except for a graveyard and a bathroom.”
In a report from Ahmad it is said: “There is no harm in offering a funeral prayer (as distinct from formal salah) in a graveyard as the Prophet, peace be upon him, himself offered a funeral prayer over a deceased while he was buried in his grave. Abu Hurairah also offered a funeral prayer over the grave of ‘Aishah in the middle of the cemetery of Al-Baqi’, which was attended by Ibn ‘Umar. And ‘Umar ibn Abd al-‘Aziz did likewise.”