Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
bayhaqi:4277Muḥammad b. Mūsá b. al-Faḍl > Abū al-ʿAbbās Muḥammad b. Yaʿqūb > Muḥammad b. Hishām > Marwān b. Muʿāwiyah > Ḥumayd > Anas

[Machine] One day, I stood up to pray and in front of me was a grave that I couldn't feel. So Umar (may Allah be pleased with him) called out to me saying "O grave, O grave." I thought he was referring to the moon, but someone who was near me informed me that he was referring to the grave. So I moved away from it. And we were narrated from Abu Dhabyan from Ibn Abbas that he disliked praying towards a wall, bathroom, or grave, all of which are disliked if it is not known that there is impurity on the body or clothing in the place that will be affected. Because in this hadith it was narrated from the Prophet ﷺ that the earth was made pure and a mosque for me, and wherever a man catches up with prayer, he should pray wherever he is.  

البيهقي:٤٢٧٧أنبأ مُحَمَّدُ بْنُ مُوسَى بْنِ الْفَضْلِ ثنا أَبُو الْعَبَّاسِ مُحَمَّدُ بْنُ يَعْقُوبَ ثنا مُحَمَّدُ بْنُ هِشَامٍ ثنا مَرْوَانُ بْنُ مُعَاوِيَةَ ثنا حُمَيْدٌ عَنْ أَنَسٍ قَالَ

قُمْتُ يَوْمًا أُصَلِّي وَبَيْنَ يَدِيَّ قَبْرٌ لَا أَشْعُرُ بِهِ فَنَادَانِي عُمَرُ الْقَبْرَ الْقَبْرَ فَظَنَنْتُ أَنَّهُ يَعْنِي الْقَمَرَ فَقَالَ لِي بَعْضُ مَنْ يَلِينِي إِنَّمَا يَعْنِي الْقَبْرَ فَتَنَحَّيْتُ عَنْهُ وَرُوِّينَا عَنْ أَبِي ظَبْيَانَ عَنِ ابْنِ عَبَّاسٍ أَنَّهُ كَرِهَ أَنْ يُصَلَّى إِلَى حَشٍّ أَوْ حَمَّامٍ أَوْ قَبْرٍ وَكُلُّ ذَلِكَ عَلَى وَجْهِ الْكَرَاهِيَةِ إِذَا لَمْ يُعْلَمْ فِي الْمَوْضِعِ الَّذِي تُصِيبُهُ بِبَدَنِهِ وَثِيَابِهِ نَجَاسَةٌ؛ لِمَا رُوِّينَا فِي هَذَا الْحَدِيثِ الثَّابِتِ عَنِ النَّبِيِّ ﷺ جُعِلَتْ لِيَ الْأَرْضُ طَيِّبَةً طَهُورًا وَمَسْجِدًا وَأَيُّمَا رَجُلٍ أَدْرَكَتْهُ الصَّلَاةُ صَلَّى حَيْثُ كَانَ