The idea of unity of time and unity of place comes from Aristotle's Poetics. In discussing the difference between an epic and a tragedy, Aristotle defines unity of time, place, and action.
In Poetics, Aristotle says epics and tragedies differ. While epics can cover long periods of time and are set in many different places, tragedies should have unity of time and place. The events of a tragedy, ideally, should "as far as possible, confine [themselves] to a single revolution of the sun." Obviously, the events of Hamlet take more than 24 hours, but when compared to the Epic of Gilgamesh or The Odyssey, Hamlet's timeline is not unbelievably long to an audience watching the play.
In addition, the action of a play should all take place in the same general physical setting. At it's most extreme, this looks like Oedipus Rex, where all the action of the place takes place outside the castle. Anything that happens away from that setting is not shown by the actors, but related through the dialogue. In Hamlet, most of the action is in or around the royal court in Elsinore, Denmark. When Hamlet goes to England, for example, the audience doesn't see any of that; they just hear about it afterwards, back in Denmark. In this way, Hamlet has unity of place as well.