From what the church teaches, when in serious sin, we have lost all rights to merit.
And we have also lost all of the merits and rewards gained thus far in our life.
Once out of serious sin, we regain those lost merits and rewards in our past life.
The reason we do not gain any merit when in serious sin is that we have lost Christ living within us, his sanctifying grace, his divine life. The cause of our merits is that we are other sons of the Father reflecting the life of his only begotten son. If we do not reflect or have that life of his only begotten Son, our efforts no longer have the power to merit.
If we pray for others in the state of serious sin, then God probably will take pity on us, and use those prayers, whatever they may be, to draw us back into the beauty of his son which we lost. But as far as doing others any good, anything is possible because God is merciful. But we cannot merit for others if we ourselves have lost the power to merit.
But even tho a person is in serious sin, they should continue to do good. For God is all just and will reward us in a natural way although not in a supernatural way. I believe we can see this time and again by people who are not holy but do good for others. They seem sometimes to thrive, and christians complain that God seems to love those who ignore him more than they do who love him. But it must be remembered, they are getting their reward now and not latter in his kingdom.
May God bless and keep you. May God’s face shine on you. May God be kind to you and give you peace.