This is some interesting status play. (For those reading who are not trained in practical status work in theatre, playing with levels of status can keep many a scene alive and some status play is written right in. This is one of those. If you want to learn more about this, Keith Johnstone’s book on Impro is fabulous.)
It’s interesting because Hamlet objectively has the higher status. He is the Prince and heir apparent. But Osric comes in and raises his own status by welcoming Hamlet home. Hamlet responds, not by raising his status, but by lowering it – by thanking Osric with humility. His humble thanks outwardly lower his status while inwardly, his status rises, because the humility is so performative. The toying begins here and will go to such extremes once the hat play commences.