Is it permissible to pray in a mosque where the ground floor is controlled by the Shi‘ah and the Sunnis control the upper floor?
Question

Here in Azerbaijan there is a city in which there is only one mosque. This mosque was built at the end of the nineteenth century, and as you know, the majority in Azerbaijan are Shi‘ah, and that is also the case in this city.
We found out that the mosque in this city was built by six people, two of whom were Shi ‘ah, and the others are unknown to us. The grandson of one of them said that they built this mosque for the travellers to worship in, and as a place for them to stay overnight.
During the Soviet occupation, this mosque was shut down and turned into a warehouse, then after that they used it as a library.
After the fall of the Soviet government, they began to use it as a mosque again, and they built a second floor to it.
At that time the (Salafi) da‘wah spread, praise be to Allah, and those who responded to the Salafi da‘wah began to come to this mosque and offer prayers in congregation there, as well as Jumu‘ah prayer, and they held classes and did other good works there, and the Shi‘ah also used to come to the mosque and pray there.
In 2003 the Salafi daa‘iyahs were put in prison, and the Shi‘ah took advantage of that and took over the mosque. But a few years later, the numbers of Salafis increased again, and they gathered on the second floor.
Now the Salafis pray Jumu‘ah on the second floor, and they have an imam, and the Shi‘ah pray on the ground floor, and have their own imam.
Some people claim that praying in this mosque is not permissible, because the one who built it was a Shi‘i, and the mosque of the Shi‘ah comes under the same rulings as masjid ad-diraar.
The second argument they present is that the Shi‘ah ascribe partners to Allah in this mosque, and they call upon their imams, and they do ‘Ashoora’ there, hence it is not permissible to pray in it, and it comes under the same ruling as (masjid ad-diraar).
Our situation at present is that we have no place except this mosque, and the government will not give us permission to build another mosque, and the brothers gather in this mosque to offer prayers in congregation, to pray Jumu‘ah and to study together and call people to Islam; even many of the Shi‘ah have responded to the call and become Muslim.
If the brothers leave the mosque, the Shi‘ah will take advantage of that, and basically that is what they want.
What is the Islamic ruling on this situation?
Praise be to Allah.Firstly: 
The fact that the Shi‘ah participated in the building of this mosque does not mean that one cannot pray in it. 
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said: 
As for simply building mosques, it is permissible for them to be built by righteous and evildoers, Muslims and non-Muslims. 
End quote from Majmoo‘ al-Fataawa (17/499) 
Shaykh Saalih al-Fawzaan (may Allah preserve him) was asked: 
Is it permissible to pray in a mosque that was built by a non-Muslim at his own expense? 
He replied: 
There is nothing wrong with that, so long as it was not done for an ulterior motive such as calling people to disbelief and so on. If it was built without any ulterior motive, then there is nothing wrong with praying in it. 
End quote.
If prayer offered in a mosque that was built by a disbeliever is valid, then it is more appropriate that prayers offered in a mosque in which some followers of innovation participated in the construction thereof should also be valid. 
The view of those who say that it is not permissible to pray in this mosque because the Shi‘ah are the ones who built it is a view that is not correct. 
Secondly: 
Allah, may He be exalted, says (interpretation of the meaning):
“And the mosques are for Allah (Alone), so invoke not anyone along with Allah” [al-Jinn 72:18].
So the Muslims must defend the houses of Allah which He has caused to be built and His name to be mentioned therein, and which He has described as His by way of honour, and not give them up to disbelievers or followers of innovation. 
Because the dispute concerning this mosque is between two groups, one of which follows correct Salafi ‘aqeedah and the other follows a deviant ‘aqeedah, it is essential for the followers of the sound ‘aqeedah to hold on to it and not leave it for the followers of innovation and deviance, especially as there is no other mosque in the city apart from this one, and it is not possible to build another, for if the followers of true faith leave it for the followers of innovation, they will end up without a mosque, and they will be leaving the house of Allah to these deviants to establish their innovation in it, and they may ascribe partners to Allah in it. 
If it so happens that the Sunnis are only able to have control of the upper floor of this building, undoubtedly this is better for them than not having any place at all, and it is better for them than being deprived of a place in which they can hold their Jumu‘ah prayers and daily prayers in congregation, and spread their call to Allah. So they have to hold onto it and not give it up or hand it over to this deviant group. Their prayers in that place are valid and their worship therein is acceptable, in sha Allah. It is clear from the question how important it is that there be a Sunni presence in that place, because they had a good influenced on others and some people embraced the way of the salaf and have given up their innovation. Allah, may He be exalted, says (interpretation of the meaning): “So keep your duty to Allah and fear Him as much as you can” [at-Taghaabun 64:16]. 
Shaykh as-Sa‘di (may Allah have mercy on him) said: 
This verse indicates that if an individual is unable to do an obligatory duty, it is waived in his case, but if he is able to do part of what is enjoined and unable to do part, then he must do whatever he is able to do, and what he is not able to do is waived in his case, as the Prophet (blessings and peace of Allah be upon him) said: “If I instruct you to do something, then do as much of it as you can.” Agreed upon. 
This shar‘i principle is applicable to innumerable minor issues. 
End quote from Tafseer as-Sa‘di (p. 86 8) 
Undoubtedly leaving this place completely in the hands of the Raafidis would constitute barring the path of Allah, as is quite obvious to any wise person, and would be a cause of many Sunnis giving up Jumu‘ah prayer and prayers in congregation altogether, so that they would not offer these prayers with the Raafidis. 
It would also be a cause of enabling the followers of innovation to establish their call without any of the Sunnis standing up to them. 
Masjid ad-diraar is the mosque that was built on a basis of disbelief and hypocrisy, and to cause division among the believers and help the hypocrites and disbelievers. What does this have to do with crowding out the followers of falsehood and saving part of the mosque so that the name of Allah may be mentioned therein and His symbols may be venerated? 
All of this is based on the assumption that the two floors are connected, with no division between them. But if the upper floor is completely separate from the lower floor, such as if the space is above the mosque and is separate from it, then that is less likely to cause confusion. In that case these are two completely separate mosques, each of which comes under its own ruling, according to the purpose for which it was built and the rituals that are conducted in it. 
And Allah knows best.