If there is a person who did a serious sin (like suicide) because of some mental illness. So basically he/she is already dead. So can't ask for forgiveness. But you don't want to see that person in Hellfire. So can Allah forgive Him/Her because of me praying for Him/Her for forgiveness and Will Allah accept that forgiveness for Him/Her forgive that person and let that person enter in Heaven?
As long as the deceased died believing in Islam, it is permissible and recommended to make dua for them. Doing so is taught in the Quran and Sunnah:
والذين جاءوا من بعدهم يقولون ربنا اغفر لنا ولإخواننا الذين سبقونا بالإيمان
And those who came after them, saying, Our Lord, forgive us and our brothers who preceded us in faith
ربنا اغفر لي ولوالدي وللمؤمنين يوم يقوم الحساب
Our Lord, forgive me and my parents and the believers the Day the account is established."
اللهم اغفر لحينا وميتنا
O Allah! Forgive our living and our deceased.