Assalaamu alaykum. Please quickly answer me without referring to another fatwa. Our bus stops for the prayer on the road by a masjid. There is a shrine of a saint outside that masjid. There is no image or grave inside the masjid. There is also no graveyard in front, nor to the left or the right side, of the masjid, but there is a graveyard and the shrine (stated above) behind the masjid. I ignore whether the masjid was built to honor the shrine or not. Is my prayer valid if I pray there?
All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
If the matter is as you described, that the grave is behind the masjid and thus outside of it, then prayer in it is valid. Your doubt as to whether the masjid was built to honor the shrine or not does not affect the validity of the prayer. What counts is that there is no grave inside the masjid.
Shaykh Al-Islam Ibn Taymiyyah said, "If the masjid is separate from the grave, then the ruling on it is the same as that on all other masjids." [Majmooʻ Al-Fataawa]
Allah knows best.
You can search for fatwa through many choices