who used to turn the graves of their prophets and eminent figures into places of worship, and because it involves venerating the dead and bears a resemblance to idol-worship. If the grave is situated on the qiblah side, the disapproval is more severe than if it lies to the right or left; and if it is behind the worshipper, the ruling is lighter than all of that, yet it is still not free of censure.”
In Sharʿat al-Islām, one of the authoritative Ḥanafi works, we read (p. 569): “It is disliked to build a mosque over a grave in which people pray.”
This unqualified statement corroborates the positions we have already cited from the scholars, and a similar wording was mentioned earlier from Imām Muḥammad, may Allah have mercy on him (p. 55).
These quotations therefore support our conclusion that performing prayer in mosques built over graves is disliked in all circumstances, whether or not one faces the grave. It is, however, essential to distinguish this issue from praying toward a grave over which no mosque has been erected: in that case the dislike applies only when the grave is directly faced. Some scholars, nonetheless, did not even stipulate facing; they ruled that prayer anywhere around the grave is prohibited.
176