What is the ruling on praying towards (in the direction of) prohibited places?
Chapter on Praying with Impurity and Other Matters
Al-Mughni
Book of Prayer
Primary text
It is disliked (Makruh) to pray towards prohibited places, but the prayer remains valid if performed. Ahmad stated that a grave, a dung heap, or a bathhouse should not be in the line of prayer (Qiblah), but if they are, the prayer suffices. A second opinion suggests repetition is required due to the prohibition, while a third holds the prayer is valid because the person did not pray within the prohibited location itself. The sound view is that there is no harm in praying towards any of these places except the cemetery.
Supporting text
The prohibition against praying towards graves is specifically established by the Hadith, "Do not pray towards graves, nor sit by them." This is due to the prohibition against taking graves as places of worship or imitating those who venerate them, which is a specific prohibition that does not extend to other prohibited locations where the reason for prohibition might be impurity or being a site of impurity.