The name "Hamlet" has no biographical connection to William Shakespeare. It is solely the protagonist's name in his tragedy Hamlet (c. 1599–1601), inherited from the Scandinavian Amleth legend.
The Hamnet/Hamlet coincidence has sparked speculation, but no evidence links them beyond phonetic resemblance. The name is literary, not autobiographical.