As for the first sense, Ibn Ḥajar al-Haytamī said in al-Zawājir (1/121):
“To take a grave as a mosque means to pray upon it or toward it.”
This is an explicit statement indicating that he understands the expression to cover two meanings, one of which is performing the prayer on the grave itself.
Al-Ṣanʿānī wrote in Subul al-Salām (1/214): “Taking graves as mosques is broader, whether that refers to praying toward them or praying upon them.”
I say: that is, it includes both interpretations—and it may well be that he had all three in mind, which is the view Imām al-Shāfiʿī, Allah’s mercy upon him, also adopted. His exact words will appear shortly. Several hadiths attest to the first meaning:
First: on the authority of Abū Saʿīd al-Khudrī, who reported that “the Messenger of Allah ﷺ forbade building over graves, sitting on them, or praying on them.” (1)