Why is Hamlet given a military funeral?
He gets a military funeral in order to show that, because he finally acted, he emerged as a better and different person. Fortinbras, whose action is contrasted with Hamlet's earlier inaction, is at the funeral and praises Hamlet. More info at the link below.
Hamlet is Prince of Denmark.His uncle had usurped his father's throne after murdering him.In the end when the conspiracy is revealed and hamlet murders his uncle . Unfortunately he himself is injured in the duel and he dies. After his uncle's death he ascends his father's throne and is given a military funeral by Fortinbras,Prince of Norway who admires Hamlet.
It was to show that Hamlet was a changed man and was well honored by many others for his courage and his bravery so by giving him the military funeral, it was to show their respect towards him and they were trying to appease the medival code of honor and satisfying the Christian expectation of forgiveness