The answer to this question has its origins back in Act 4 when Hamlet sees Fortinbras and his army marching toward their battle in Poland. Hamlet asks several questions about this battle and learns that Fortinbras is heading into a fight over a piece of worthless land, and Hamlet seems to question why so many men would so willing go to their deaths for that, but realizes that there must be something rather inspirational about Fortinbras that he can convince his army to do it. In that scene he calls Fortinbras a "delicate and tender prince" and while I don't know if that is really true, (remember that he was originally planning an attack on Denmark with a bunch of mercenaries!) Hamlet's perception is what matters and what influences his decision in Act 5. He respects that Fortinbras is taking strong action for something more about the honor than actual physical or monetary gain. Hamlet has been acutely aware of his inability to act for the honor of his father and clearly sees what a foil Fortinbras is to himself.
In Act 5, after Claudius's death, Hamlet is technically King for about 5 minutes and in those 5 minutes he does what he thinks is best for Denmark. He leaves Denmark in the strong and determined hands of a noble man who is able to form a plan and carry it out; who seems fearless; who acts for honor's sake; and who Hamlet thought was fine prince. While it is not ideal to leave the kingdom in the hands of a foreigner, what other viable options are left? Horatio is not noble and not Danish. The kingdom of Denmark with the loss of its entire noble family would be thrown in political and social chaos if strong leadership doesn't take the reigns, and Hamlet ensures that that is what happens.