William Shakespeare's character Hamlet and the play by the same name are heavily based on the Danish mythological figure Amleth. Saxo Grammaticus penned the Sags of Amleth in the twelfth century, and Shakespeare must have either read this story or become very familiar with it by other means. While he could have chosen a different name but retained some of the original themes of the Saga, he chose to Anglicize the name of the Prince of Denmark as Hamlet.
It has also been suggested that Shakespeare chose the name Hamlet in honor of his only son, Hamnet. The two names may have been interchangeable in Elizabethan times, as both are Anglicized versions of the Danish Amleth. Hamnet Shapespeare died in 1596, and the play Hamlet was written sometime between 1599 and 1602. Shakespeare may have also expressed his grief in the play King John, written the same year as Hamnet's death and detailing the grief of a mother who has just lost her son.
Grief fills the room up of my absent child,
Lies in his bed, walks up and down with me,
Puts on his pretty looks, repeats his words,
Remembers me of all his gracious parts,
Stuffs out his vacant garments with his form.