Tess of the D’Urbervilles and Billy Budd were both finished by 1891, when Melville died and Tess was published. In each of these two books a guileless and naive, but not necessarily legally innocent protagonist is condemned to death and hanged for the murder of a malicious villain. Both of the condemned were, in addition, young and physically attractive.
Were these two books triggered by a real-life incident? A little digging reveals that Melville began his novel in 1886, while Hardy started planning his in the fall of 1888. However, Melville’s first version had a much older protagonist; in 1888 he began a second draft featuring a young Billy Budd
I am reasonably sure that no one has discovered a possible real-life source for the two books (or as far as that goes, even looked for one). I’ve seen a suggestion that Melville may have had the 1886 hanging of the Haymarket anarchists in mind, or certain naval mutinies, but it seems unlikely that these had anything to do with Hardy’s book.
This question should be easy enough to answer. The triggering event would have taken place in fall 1888 or the year or so before that, since that was when Hardy began his novel and Melville began his new version with the young Billy. A look through the newspaper archives should do it, one way or another.
Victor Verney (link) has steered me to the 1842 mutiny on the training ship USS Somers. Three young men were accused of a plan to take over the ship and and turn pirate, and Melville’s cousin Guert Gansevoort was one of the presiding officers at the trial which ordered them to be hanged. So it looks like I’ll have to play the overdetermination card. Melville obviously had more than one hanging in mind when he wrote Billy Budd, so I’ll limit my claim to the possibility that the timing of the book was influenced by some other hanging in 1887 or 1888.