The answer is:
in act 6, scene 4, it is made explicit the advice that Hamlet gives to Gertrude. He wants Gertrude to repent having married to her ex-husband's brother, who was deceased and did not stay with him (Hamlet's uncle) in the future.
Hamlet consider that if she does it so, that would be virtuous, and wise.