Praise be to Allah.
It is prescribed to offer supplication for the Muslims, males and females, seeking the best of this world and the hereafter for them. This is one of the meanings of the brotherhood and bonds of faith that exist among Muslims, for the Muslim should love for his brother what he loves for himself of good. Hence he should pray for all the Muslims, seeking the best of this world and the hereafter for them.
If a Muslim offers supplication for his Muslim brothers in general, there is the hope that the blessing of this supplication will benefit all of them.
Al-Bukhaari (831) and Muslim (402) narrated that Ibn Mas‘ood (may Allah be pleased with him) said: When we prayed behind the Prophet (blessings and peace of Allah be upon him), we used to say: Peace (salaam) be upon Jibreel and Mikaa’eel, peace be upon So and so and So and so. The Messenger of Allah (blessings and peace of Allah be upon him turned to us and said: “Allah is as-Salaam, so when one of you prays, let him say: al-Tahiyyaatu Lillaahi wa’l-salawaatu wa’l-tayyibaat; al-salaamu ‘alayka ayyuha’l-nabiyyu wa rahmat-Allahi wa barakaatuhu; al-salaamu ‘alayna wa ‘ala ‘ibaad-illaah il-saaliheen (All compliments, prayers and good words are due to Allah; peace be upon you, O Prophet, and the mercy of Allah and His blessings; peace be upon us and upon the righteous slaves of Allah).”
If the Muslim intends to offer supplication for a particular person, then offers supplication for the Muslims in general, there is the hope that his supplication will benefit all of them.
Abu Daawood (3201) narrated that Abu Hurayrah said: The Messenger of Allah (blessings and peace of Allah be upon him) offered the funeral prayer and said: “O Allah, forgive our living and our dead, our young and our old, our male and our female, our present and our absent ones. O Allah, whomever You give life among us, cause him to live as a believer and whomever You cause to die among us, cause him to die in Islam. O Allah, do not deprive us of his reward and do not cause us to go astray after that. Classed as saheeh by al-Albaani in Ahkaam al-Janaa’iz (1/124).
Al-Qaari (may Allah have mercy on him) said:
At-Teebi said: What is meant by the four pairs [in the hadith quoted above] is to include everyone; it is not be interpreted as being only for these four pairs. It is as if he is saying: O Allah, forgive the Muslim men and women, all of them.
End quote from Mirqaat al-Mafaateeh (3/1208).
Ibn ‘Allaan (may Allah have mercy on him) said:
“O Allah, forgive our living and dead” means: all of our living and dead, among the Muslims.
End quote from Daleel al-Faaliheen (6/416).
It says in Fiqh al-Ad‘iyah wa’l-Adhkaar (3/232):
This is a great supplication which includes the one for whom the funeral prayer is being offered, as well as other Muslims, both living and dead, young and old, male and female, those who are present and those who are absent, because they all share the same need and, indeed, the necessity of Allah’s forgiveness, pardon and mercy. End quote.
For more information, please see the answer to question no. 140798.
And Allah knows best.