I heard the Messenger of Allah ﷺ say, "Do not pray facing graves, and do not sit upon them."
سمعت رسول الله ﷺ يقول: لا تصلوا إلى القبور، ولا تجلسوا عليها.
Muslim narrated it in the Book of Funerals (972) via Wathila bin Asqa, from Abu Marthad, who mentioned something similar. The people of knowledge said, Prayer is disliked toward graves, upon graves, and between graves.