But I am so glad you asked the question. I now see the question (one posed sometimes by non-believers) as a trick question.
It is a trick because it comes in the form of a philosophical question, to which, as we saw above, the short answer is, “if we are to have free will, man must be able to reject God with his last decision.” Then, the trick (which you stepped into above) comes with the follow-up is “that doesn’t seem fair or right when a man’s life has been virtuous previously.” This part is a trick because it allows someone to create the impression that God is unfair and unmerciful. But as was fleshed out above, in fact the hypothetical is contrived.
So another way of responding to this issue (forgive me if I a repeating a response above), is to say: Man has free will, but do not think that the freedom to reject heaven at the end of life indicates that God is unfair or unmerciful. We have a loving and merciful God. (Quote Jn. 3:16). He sent his only son, who is the life, the truth, and the way, to be our guide. He taught us to take up our cross and follow him. He told us to take the yoke with him, for it is light. His son established the Church to help guide us. Those of us who have accepted the invitation to follow Christ, believe his Father to be infinitely merciful and loving.
I wonder if there is one additional point to make. If someone should say, “well I understand that you believe your god is merciful, but I believe otherwise,” it seems to me that we could respond as follows: “It is not for you to have an opinion regarding my God’s mercy because you have rejected him.”
Thanks again, and Peace.