Many of the characters in Hamlet are collegiate types. Hamlet has spent years at Wittenberg and would like to go back there to continue his studies if the King would let him. In fact, Hamlet seems like the type of studious young man who might stay at the university indefinitely. He may not object to Claudius becoming king if only Claudius wasn't keeping him a virtual prisoner at Elsinore.
Rosencrantz and Guildenstern are both students at Wittenberg and are only visiting Elsinore because Claudius has summoned them to help him find out the reason for what he calls Hamlet's "transformation." Horatio is also a student at Wittenberg. He tells Hamlet he came to Elsinore to attend Hamlet's father's funeral. Even Polonius attended a university, as he tells Hamlet in Act III, Scene 2. Polonius's son Laertes leaves to attend the university in France. No doubt Osric, with his big vocabulary, is also a college graduate.
Shakespeare seems to be drawing a contrast between college and the real world, especially for Hamlet. The university is sheltered, secluded, and idealistic. The real world is full of deceit and corruption. Hamlet has difficulties adjusting to the cold, hard facts of reality. He finds that his father has been murdered, his uncle has usurped the throne, and that Claudius has committed what Hamlet considers incest by marrying Hamlet's mother. Hamlet is quickly disgusted with the real world represented by Elsinore. In Act I, Scene 2, he says to himself:
How weary, stale, flat and unprofitable
Seem to me all the uses of this world!
Fie on't! ah, fie! 'tis an unweeded garden
That grows to seed; things rank and gross in nature
Possess it merely.
College students typically are in for a rude shock when they graduate and go out into the real world to join in the universal struggle for survival. The rules and values they learn in college do not apply to the real world. This, apparently, is what Shakespeare intended to show as happening to Hamlet.