During my travels outside the Muslim world, it happens that I pass by graves, is it permissible to recite the cited supplication (when passing by the Muslims graves). Please note that I do not know whether they are Muslims’ graves or not.
All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
The individual who passes by graves may be one of three case;
The first case: if he is certain or almost sure that they are Muslim graves; for instance, when the majority of the inhabitants of that town are Muslims, it is recommended to recite the supplication.
The second case: if he is certain or almost sure that they are the graves of non-Muslims; for instance, when all or most of the city inhabitants are disbelievers, he must not recite the supplication for it is prohibited to greet them. Rather, it is recommended to give them the bad tidings of Hell fire for the saying of the Messenger of Allaah, sallallaahu ‘alayhi wa sallam: "Wherever you pass by a disbeliever’s grave give him bad tidings of Hell fire." [Ibn Maajah and others, classed as Saheeh by Al-Albaani]
The third case: if he is completely unsure whether the inhabitants are Muslims or non-Muslims, then he may recite the supplication intending to greet the Muslims assuming that they are buried in these graves.
Allaah Knows best.
You can search for fatwa through many choices