بسم الله الرحمن الرحيم
It is must to strictly follow the intention of endowers (doers of waqf):
قال فی الشامی: مراعاة غرض الواقفين واجبة (ج 3، ص 464 الدر مع الرد) وقال ايضا شرط الواقف كنص الشارع اى فى المفهوم والدلالة (ج 3، ص 456 الدر مع الرد)
Those who do jamat in Yatim Khana instead of mosque cause rift between Muslims as well it is deprivation from the reward of mosque. However, it is not unlawful if you sometime offer salah in Yatim Khana, but it is unlawful to turn the Yatim Khana (orphanage) into mosque as it is against the intention of the endower. When the papers of Yatim Khana Trust are with you then you should solve the problem along with some serene persons. Those who want to build another mosque they should buy land somewhere else and construct the mosque there.
Allah knows Best!
Darul Uloom Deoband