بسم الله الرحمن الرحيم
A graveyard that is waqf for the burial of dead ones it must be used for the same purpose.
لإن مراعاة غرض الواقفين واجبة، وشرط الواقف كنص الشارع
So in the question mentioned above, if dead bodies are buried in the graveyard then it is not lawful to construct shops and give on rent. The expenses of the graveyard and the salary of Imam should be arranged by some other means.
Note: The answer is correct. In order to save the graveyard from illegal encroachment, boundary wall should be erected.
Allah knows Best!
Darul Uloom Deoband