The source material is from a Danish history in which is recorded the ancient legend of Amleth, Price of Denmark. Shakespeare sets Hamlet in the mid- to late-1500s, after the Protestant Reformation of 1517.
What has historical implication are the details that Shakespeare added about King Hamlet being Catholic, as indicated by dying without blessing and being in purgatory. English citizens were mandated to join the protestant Church of England so the Danmark-set drama opposing Catholic and Protestant would resonate with his English audience.
Hamlet, Prince of Denmark, was studying at the Protestant university of Wittenburg, the university of reformer Martin Luther. Being Protestant sets up the internal and external conflict with his Catholic father's ghost that fuels the tragedy and Hamlet's inactive, contemplative approach to his dilemma.
This transition between Catholicism and Protestantism affected his way of thinking by calling into question the very premise motivating the Ghost and underlying the cultural norm of revenge killing.
Based on an ancient Danish legend about an ancient Prince named Amleth, Hamlet was first performed in 1601 or 1602, during the last year of the reign of Elizabeth I. As Elizabeth I had no heir, the possibility of a fight over the throne and a renewal of fighting between Catholic and Protestant occupied the thoughts of many Englishmen.
Hamlet is a play in which the fight over control of a county ultimately leads to the county being taken over by a foreign power. Some critics suggest that Shakespeare was warning England not to repeat the struggle over the throne that occurred after the death her father, Henry VIII. A fight over the throne after the death of Elizabeth I would weaken the country and possibly allow Spain a renewed chance to gain power.
Fortunately for England, a fight was avoided when James VI of Scotland took over the English throne and became King James II of England while retaining the Scottish monarchy as King James VI of Scotland.