Sahih Muslim 2251
The Book of Prayer - Funerals
وَحَدَّثَنَا حَسَنُ بْنُ الرَّبِيعِ الْبَجَلِيُّ، حَدَّثَنَا ابْنُ الْمُبَارَكِ، عَنْ عَبْدِ الرَّحْمَنِ بْنِ يَزِيدَ، عَنْ بُسْرِ بْنِ عُبَيْدِ اللَّهِ، عَنْ أَبِي إِدْرِيسَ الْخَوْلاَنِيِّ، عَنْ وَاثِلَةَ بْنِ الأَسْقَعِ، عَنْ أَبِي مَرْثَدٍ الْغَنَوِيِّ، قَالَ سَمِعْتُ رَسُولَ اللَّهِ صلى الله عليه وسلم يَقُولُ " لاَ تُصَلُّوا إِلَى الْقُبُورِ وَلاَ تَجْلِسُوا عَلَيْهَا" .
Abu Marthad al-Ghanawi reported Allah's Messenger (ﷺ) as saying:Do not pray facing towards the graves, and do not sit on them
Text from the public-domain hadith-api dataset. Numbering follows that dataset and can differ by a few from some printed editions — check the wording, not only the number.