Do not sit on the graves and do not pray facing towards them.
The Book of Prayer - Funerals
Sahih Muslim 972 a
Prohibition of Sitting on Graves
The prohibition against sitting on graves stems from the need to honor the deceased and maintain the sanctity of their resting places. The graves are the abodes of our Muslim brothers and sisters who are undergoing the trials of the grave. To sit upon them would be a form of disrespect to both the deceased and the sacred nature of death itself, which serves as a reminder of our own mortality and the Hereafter.
Prohibition of Praying Facing Graves
The prohibition against praying facing graves is to safeguard the purity of Islamic monotheism (tawhid) and prevent any resemblance to the practices of those who worship graves or seek intercession from the dead. Our prayers must be directed solely to Allah, and facing graves during prayer could lead to misunderstandings or innovations that contradict the fundamental principle of directing all worship to Allah alone.
Scholarly Commentary
These prohibitions are established through authentic narrations and represent the consensus of the early Muslim community. They serve to protect both the rights of the deceased and the correct practice of Islamic worship. The wisdom behind these rulings becomes clear when we consider that excessive attachment to graves has historically led to shirk (associating partners with Allah) in many communities.