Sayyiduna Anas (may Allah be pleased with him) said: I was standing in prayer and there was a grave in front of me, which I was not aware of. Sayyiduna Umar (may Allah be pleased with him) called out to me: "The grave, the grave!" I kept thinking he was saying "the moon". Those near me told me that he meant "the grave", so I moved away from it.
(b) Sayyiduna Ibn Abbas (may Allah be pleased with them both) disliked praying facing a toilet, a bathhouse or a grave.
(c) All of this is by way of dislike, as long as no impurity is known in the spot that one's body and clothes touch, because of what is established from the Prophet (peace and blessings be upon him) in the hadith: "The earth has been made pure, a means of purification and a mosque for me; so any man whom the time of prayer reaches should pray wherever he is."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4277