Hadith: Those are a people who, when a righteous slave or a righteous man from among them dies, they build a place of worship over his grave and place those images therein. They are the most evil people in the sight of Allah
عن عائشة - رضي الله عنها-، أن أمَّ سَلَمَة، ذَكَرَت لرسول الله صلى الله عليه وسلم كَنِيسة رأتْهَا بأرض الحَبَشَةِ يُقال لها مَارِيَة، فذَكَرت له ما رأَت فيها من الصُّور، فقال رسول الله صلى الله عليه وسلم :«أولئِكِ قوم إذا مات فيهم العَبد الصالح، أو الرُّجل الصَّالح، بَنُوا على قَبره مسجدا، وصَوَّرُوا فيه تلك الصِّور، أولئِكِ شِرَار الخَلْق عند الله». [صحيح] - [متفق عليه] المزيــد ...
‘Ā’ishah (may Allah be pleased with her) reported that Umm Salamah mentioned to the Messenger of Allah (may Allah's peace and blessings be upon him) that she had seen a church in Abyssinia called Māriyah, and she mentioned the images that she had seen therein. The Messenger of Allah (may Allah's peace and blessings be upon him) said: "Those are a people who, when a righteous slave or a righteous man from among them dies, they build a place of worship over his grave and place those images therein. They are the most evil people in the sight of Allah." Sahih/Authentic. - [Al-Bukhari and Muslim]
‘Ā’ishah (may Allah be pleased with her) tells us that while Umm Salamah (may Allah be pleased with her) was in Abyssinia, she saw a church that had images inside of it. She mentioned to the Messenger of Allah (may Allah's peace and blessings be upon him) what she had seen of the beautiful embellishments and images, and she was amazed at that. Due to the significance of the matter and its danger to pure monotheism, the Prophet (may Allah's peace and blessings be upon him) raised his head and explained the reasons for placing these images in order to warn his Ummah against what those people did, saying:"Those people whom you mentioned, when a righteous man from among them would die, they would build a place of worship over his grave and pray therein, and they would make these images." He clarified that whoever does that is the worst of the creation in the sight of Allah, the Exalted, because doing such an act leads to associating partners with Allah, the Exalted.
It is prohibited to build mosques over graves or bury the dead in mosques, in order to block the means to polytheism and avoid imitation of idol worshipers.
Building places of worship over graves and putting images in places of worship are practices of the Jews and Christians. So, whoever does so has acted like them and deserves the punishment they deserve.
Praying at graves is a means leading to polytheism, whether the graves are located inside or outside mosques.
It is prohibited to acquire images if they are for living beings.
He who builds a mosque over a grave and puts images therein is one of the most wicked people.
The Shariah is keen on fully protecting the soundness of monotheism, as it blocks all means that may lead to polytheism.
Prayer in mosques built over graves is not valid, for the Prophet (may Allah’s peace and blessings be upon him) forbade that and cursed one who does it. Prohibition signifies voidness of the prohibited thing.
This points out the Prophet’s keenness on guiding his Ummah. It is manifested by his warning to them, while he was in his last illness, not to follow the Jews and Christians in what they did with their prophets and righteous people.