Why is the Prophet’s grave in his mosque even though it is forbidden to take graves as places of worship?
Question

                The hadeeth says, “May Allaah curse the Jews, for they have taken the graves of their Prophets as places of worship”. So how come the grave of the Prophet (peace and blessings of Allaah be upon him) is inside his mosque in Madeenah?.
Praise be to Allah.The scholars have 
      discussed this issue, in the past and more recently, and they refuted 
      those who quote the fact that the grave of the Prophet  (peace and 
      blessings of Allaah be upon him) is inside his mosque as evidence that it 
      is permissible to take graves as places of worship, or to include graves 
      in mosques. We will quote the fatwas of some of our prominent scholars, 
      which discuss in detail the matter raised in the question. 

    1 – Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allaah have mercy on 
    him) said: 

    There is a specious argument put forward by those who worship 
    graves, namely the fact that the grave of the Prophet  (peace and 
    blessings of Allaah be upon him) is in his mosque. The answer to that is 
    that the Sahaabah (may Allaah be pleased with them) did not bury him in his 
    mosque, rather they buried him in the house of ‘Aa’ishah (may Allaah be 
    pleased with her). When al-Waleed ibn ‘Abd al-Malik expanded the Mosque of 
    the Prophet  (peace and blessings of Allaah be upon him) at the end of 
    the first century, he incorporated the room into the mosque, but he did 
    wrong thereby, and some of the scholars denounced him for that, but he 
    believed that there was nothing wrong with it for the sake of expanding the 
    mosque. 

    It is not permissible for a Muslim to take that as evidence 
    that mosques may be built over graves, or that people may be buried inside 
    mosques, because that goes against the saheeh ahaadeeth, and because it is a 
    means that may lead to shirk by associating the occupants of the graves in 
    worship with Allaah.  End quote. 

    Majmoo’ Fataawa al-Shaykh Ibn Baaz, 
    5/388, 389. 

    2 – Shaykh Muhammad ibn Saalih al-‘Uthaymeen (may Allaah have 
    mercy on him) was asked about the ruling on praying in a mosque in which 
    there is a grave. 

    He replied: 

    Praying in a mosque in which there is a grave falls into two 
    categories: 

    (i)Either the grave was there 
    before the mosque, and the mosque was built over the grave. It is essential 
    to shun this mosque and not pray therein, and the one who built it must 
    knock it down; if he does not do so, then the Muslim authorities must knock 
    it down.

    (ii)Or the mosque was there before 
    the grave, and the deceased was buried after the mosque was built. In the 
    case the grave must be dug up, and the remains taken out and buried with the 
    people (in the graveyard).

    As for praying in such a mosque, it is permissible so long as 
    the grave is not in front of the worshipper, because the Prophet  (peace 
    and blessings of Allaah be upon him) forbade praying in the direction of 
    graves. 

    With regard to the grave of the Prophet  (peace and 
    blessings of Allaah be upon him) which is incorporated into his mosque, it 
    is well known that the Mosque of the Prophet  (peace and blessings of 
    Allaah be upon him) was built before his death, and was not built over his 
    grave. It is also well known that the Prophet  (peace and blessings of 
    Allaah be upon him) was not buried in the mosque, rather he was buried in 
    his house which was separate from the mosque. At the time of al-Waleed ibn 
    ‘Abd al-Malik he wrote to his governor in Madeenah, who was ‘Umar ibn ‘Abd 
    al-‘Azeez, in 88 AH, ordering him to dismantle the Prophet’s Mosque and add 
    to it the rooms of the wives of the Prophet  (peace and blessings of 
    Allaah be upon him). ‘Umar gathered the prominent people and fuqaha’, and 
    read the letter of the caliph al-Waleed to them. That caused them distress, 
    and they said: “Leave it as it is, that is better.” And it was narrated that 
    Sa’eed ibn al-Musayyib denounced the incorporation of ‘Aa’ishah’s room into 
    the mosque, as if he feared that the grave would be taken as a place of 
    worship. 

    Umar wrote a letter to that effect to al-Waleed, and 
    al-Waleed sent word to him ordering him to carry out his instructions, so 
    ‘Umar had no other choice.  So you see that the grave of the Prophet  
    (peace and blessings of Allaah be upon him) was not placed in the mosque, 
    and the mosque was not built over it, so there are no grounds for those who 
    try to quote this as evidence that people may be buried inside mosques or 
    that mosques may be built over graves. 

    It is proven that the Prophet  (peace and blessings of 
    Allaah be upon him) said: “May the curse of Allaah be upon the Jews and the 
    Christians; they have taken the graves of their Prophets as places of 
    worship.” He said that as he was dying, as a warning to his ummah against 
    doing what they did. When Umm Salamah told him of a church that she had seen 
    in Ethiopia and the images therein, he said: “Those people, if a righteous 
    man among them died, they would build a place of worship over his grave. 
    They are the most evil of people before Allaah.” And it was narrated from 
    Ibn Mas’ood (may Allaah be pleased with him) that the Prophet  (peace 
    and blessings of Allaah be upon him) said: “Among the most evil of people 
    upon whom the Hour will come when they are still alive are those who take 
    graves as places of worship.” Narrated by Imam Ahmad with a jayyid isnaad. 

    The believer should not accept to follow the ways of the Jews 
    and the Christians, or to be among the most evil of people. 

    Majmoo’ Fataawa al-Shaykh Ibn ‘Uthaymeen, 
    12/question no. 292 

    And Allaah knows best.