Romeo and Juliet is believed to have been written between 1591 and 1595. Hamnet, Shakespeare's only son, died in1596, so it is unlikely that his death would have influenced the writing of Romeo and Juliet.
Death of Hamnet Shakespeare
Hamnet was eleven years old when he died, and although the precise date of his death is unknown, he was buried on 11th August 1596. Hamnet is thought to have died of the Bubonic Plague. In those days, one in three children didn't survive past the age of ten, so the death of a child was sadly not uncommon.
Hamnet's Death in Relation to Shakespeare's Works
Shakespeare had been writing comedies in the years leading up to Hamnet's death, and continued to do so for several after. He then turned to tragedies. Some scholars believe that Hamnet's death provided Shakespeare with an experience of grief that made his tragedies all the more powerful, allowing him to write some of his most renowned and poignant work, such as Hamlet.
Romeo and Juliet
In one scene, Juliet's nurse makes reference to an earthquake that occurred 11 years previously, and this is thought to refer to the Dover Straits earthquake in 1580. If this is the case, then it would suggest that the play was written in 1591. However, the play is considered stylistically similar to the plays Shakespeare was writing in 1594 and 1595, so many scholars believe that Shakespeare began his first draft in 1591 but didn't finish the play for a few more years.