Denmark is the setting of Shakespeare's Hamlet. The play opens with the king of Denmark having recently died (and it turns out murdered), the prince of Denmark upset about his father's death and his mother's (the queen of Denmark) quick remarriage, and the country itself unsettled or at least soon-to-be unsettled. Soon, things will be "rotten" in the State of Denmark. The play is all about Hamlet's quest, in effect, to purge Denmark of that rottenness. The country of Norway looms in the background because its prince wants to invade, but the story is all about royalty in Denmark.
As the setting for Shakespeare's "Hamlet," Denmark is a good choice since the important port of Elsinore provides the appropriate and convenient location for the sentinels, who sight the ghost of King Hamlet to be on guard and for the arrivals of Hamlet from Germany and, later, Fortinbras from Norway and ambassadors from England as well as the departures of Laertes for France and Hamlet for England.
In addition, Denmark in the sixteenth century grew wealthy from taxes because of the increased traffic through the Oersund which controlled both sides of the Sound. Also, the Danish economy benefited from the Eighty Years' War. Thus, because of the wealth and opportunities for wealth, the Danish court easily became very political and, consequently, corrupt. This corruption is the ideal environment for "Hamlet" as the young prince is reviled by the "something is rotten in Denmark" witnessed in the hypocritical Polonius, wicked Cladius, jaded queen, and others. Because of this corruption in the entire court, Hamlet becomes most melancholic, disgusted, and ambivalent about what actions he should take. Finally, his "soul full of discord and dismal" (IV,i,45) Hamlet, as the Prince, vows to save Denmark, instructing Horatio in his dying moments,
But I do prophesy th'election lights/On Fortinbras. he has my dying voice./So tell him, with the' occurents, moreand less/Which has solicited--the rest is silence. (V,ii,334-337)