It’s more disturbing to look at a painting of a beheading when you know that the artist had recently murdered a man.
In 1606, Caravaggio killed Ranuccio Tomassoni in Naples, possibly over a gambling debt. Caravaggio fled to Malta, where he was welcomed by the Grand Master of the Knights of Malta, Alof de Wignacourt. But being a famous painter can only get you so far, and after getting in another fight and stabbing a knight, Caravaggio was imprisoned.
So when did Caravaggio paint David with the Head of Goliath? After his jailbreak of course. Caravaggio escaped from the Knights of Malta, and traveled through Sicily and Palermo. During this time, he painted two paintings of David and Goliath — one currently on display in the Kunsthistorisches Museum in Vienna, and this one — perhaps the most controversial painting of his career. Scholars believe that in this painting, much darker and more contemplative than its twin, Goliath’s head is a self-portrait by Caravaggio. Additionally, David is thought to be a self-portrait of Caravaggio as a young man, or, a portrait of Cecco, his studio assistant and lover. Considering the angle of the sword, we're guessing it’s Cecco.
Self-portrait or not, Caravaggio sent David with the Head of Goliath to the Roman Cardinal Scipione Borghese as a request for a pardon. If you look closely, you can see the letters H-AS OS on the sword, though to be an abbreviation of the latin phrase humilitas occidit superbiam — “Humility kills pride”
Reed Enger, "David with the Head of Goliath (1610)," in Obelisk Art History, Published January 30, 2015; last modified May 19, 2021, http://arthistoryproject.com/artists/caravaggio/david-with-the-head-of-goliath-1610/.