رَبَّنَا اغْفِرْ لَنَا وَلِإِخْوَانِنَا الَّذِينَ سَبَقُونَا بِالْإِيمَانِ
Our Lord, forgive us and our brothers who preceded us in faith. (al-Ḥashr 59:10)
Believers who come later are taught to seek forgiveness for those who preceded them. This provides a Qur'anic basis for supplication benefiting the deceased.
A believer therefore asks for forgiveness not only for oneself but also for fellow believers, including those who have passed away.