Can I pray for a deceased priest but ask God that if this priest is in Heaven can he pray for me instead as he wouldn’t need my prayers?
You should always pray for the deceased. If they don’t need the prayers now, God will either backdate the prayer to help them during their life or use it to help someone else.
You should always ask the deceased to pray for you. If the priest is in Heaven then he will pray for you. If the priest is not yet in Heaven, but is in Purgatory, he might still be able to pray for you. Opinion is divided on whether souls in Purgatory can pray for people on earth; St Catherine of Genoa believed they could. Also remember that Purgatory and Heaven exist outside earthly time so for all we know there is a mechanism for you to benefit now from prayers said by the priest after he gets to Heaven.
Bottom line: answer to your question is Yes
I didn’t know that could happen.
So I could pray for my Nan now who died many years ago to ask God to have mercy on her before she dies?
You certainly could. St Padre Pio prayed for his ancestors who died years before he was born. I do the same.
Since both God and the deceased are, by definition, out of time, how would “backdating” take place?
God can apply prayers anywhere on the earthly time spectrum. “Backdating” is the word I use to describe it as it relates to my time. If I pray now for the good death of my granddad who died before I was born, God applies the prayer to my granddad at the time of his death in the 1950s. I don’t know how God does it and obviously it’s not backdating for God, who is outside time, but it is for me from my earthly perspective, because I’m within earthly time.