It's a measure of Fortinbras's innate nobility that he recognizes a kindred spirit in the deceased Hamlet. Strictly speaking, though, Hamlet wasn't a soldier; he never fought for his country. But in a way he did fight; he fought for a noble cause. Though instead of fighting a foreign power, he fought against his wicked uncle's usurpation of the Danish throne. To be sure, he took his time about it, but he got there in the end. He received his orders from his father's ghost and eventually did carry them out, although the tactics he used were far from conventional from a military standpoint.
Yet perhaps Fortinbras is mistaken as to Hamlet's true nature. He declares that Hamlet, had he lived, would've made an excellent king. But how would Fortinbras know that? The short answer is that he doesn't. In giving the deceased prince a military funeral, Fortinbras is simply showing due propriety to established tradition.
Ignoring the moral complexity of Hamlet's character is also a smart move politically. Fortinbras may not know much about what Hamlet was really like, but he does know how popular he was with the Danish people. Giving him a burial worthy of a great and noble warrior immediately puts Fortinbras on the side of his new subjects. This is a highly skillful act of propaganda that should conduce greatly to the long-term stability of Fortinbras's new throne.