This is interesting as a status transaction. We have a prince talking to a captain in the army. The prince does not reveal his status to the captain but there’s a way wherein this line sort of makes the most sense as being a high status person attempting to lower his status.
If Hamlet were a peasant, it would seem less likely that he would humbly thank someone – the humbleness might be redundant in that case. A peasant doesn’t need to humbly thank anyone – any thank you is humble.