All perfect praise be to Allah, The Lord of The Worlds, and may His peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
It is prohibited to use a graveyard for a purpose other than the one it was originally endowed for since a burial ground is considered an endowment(Waqf), and, in principle, an endowment can`t be sold, inherited, given as a present nor replaced with something else; rather, it must serve only the purpose it was endowed for.
Narrated Ibn `Umar: Umar bin Khattab got some land in Khaibar and he went to the Prophet (PBUH) to consult him about it saying, "O Allah's Messenger (PBUH) I got some land in Khaibar better than which I have never had, what do you suggest that I do with it?" The Prophet (PBUH) said, "If you like you can give the land as endowment and give its fruits in charity." So `Umar gave it in charity as an endowment on the condition that would not be sold nor given to anybody as a present and not to be inherited, but its yield would be given in charity to the poor people, to the Kith and kin, for freeing slaves, for Allah's Cause, to the travelers and guests; and that there would be no harm if the guardian of the endowment ate from it according to his need with good intention, and fed others without storing it for the future."{Bukhari&Muslim}.
Jurists have stated that the conditions set by the donor of the Waqf must be abided by. Al-Imam Ash-Shirbini said: "In principle, the conditions set by the donor are binding unless they violate the purpose of the endowment."{Moghni Al-Mohtajj, 3/54}. Moreover, "It is prohibited to replace it with something else."{Nihayat Azain, a Shafie book}.
In conclusion, it is prohibited to enlarge the mosque at the expense of the graveyard, and the latter must remain as it is. And Allah knows best.