كتاب الْمَسَاجِدِ وَمَوَاضِعِ الصَّلاَةِ
5  
The Book of Mosques and Places of Prayer
(3)
Chapter: The prohibition of building masajid over graves and placing images therein; and the prohibition of taking graves as masajid
(3)
باب النَّهْيِ عَنْ بِنَاءِ الْمَسَاجِدِ عَلَى الْقُبُورِ وَاتِّخَاذِ الصُّوَرِ فِيهَا وَالنَّهْيِ عَنِ اتِّخَاذِ الْقُبُورِ مَسَاجِدَ
Sahih Muslim 529

'A'isha reported:

The Messenger of Allah (ﷺ) said during his illness from which he never recovered: Allah cursed the Jews and the Christians that they took the graves of their prophets as mosques. She ('A'isha) reported: Had it not been so, his (Prophet's) grave would have been in an open place, but it could not be due to the fear that it may not be taken as a mosque.
حَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، وَعَمْرٌو النَّاقِدُ، قَالاَ حَدَّثَنَا هَاشِمُ بْنُ الْقَاسِمِ، حَدَّثَنَا شَيْبَانُ، عَنْ هِلاَلِ بْنِ أَبِي حُمَيْدٍ، عَنْ عُرْوَةَ بْنِ الزُّبَيْرِ، عَنْ عَائِشَةَ، قَالَتْ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم فِي مَرَضِهِ الَّذِي لَمْ يَقُمْ مِنْهُ ‏ "‏ لَعَنَ اللَّهُ الْيَهُودَ وَالنَّصَارَى اتَّخَذُوا قُبُورَ أَنْبِيَائِهِمْ مَسَاجِدَ ‏"‏ ‏.‏ قَالَتْ فَلَوْلاَ ذَاكَ أُبْرِزَ قَبْرُهُ غَيْرَ أَنَّهُ خُشِيَ أَنْ يُتَّخَذَ مَسْجِدًا ‏.‏ وَفِي رِوَايَةِ ابْنِ أَبِي شَيْبَةَ وَلَوْلاَ ذَاكَ لَمْ يَذْكُرْ قَالَتْ ‏.‏
Reference : Sahih Muslim 529
In-book reference : Book 5, Hadith 24
USC-MSA web (English) reference : Book 4, Hadith 1079
  (deprecated numbering scheme)