I think it was the French Army that would shoot some of their soldiers “pour encourager les autres”. I doubt if any British admirals were hanged — ordinary seamen, yes, but admirals were few and far between, and members of the elite, don’t you know.
After I posted it, the hanging part gave me second thoughts. There was a famous case of the British controversially executing an admiral in the 18th century, but he was shot, not hanged. (Shooting was considered a more honorable way to go.)
I remember seeing a picture of him blindfolded, dropping the handkerchief as the signal to fire. Ah yes, here it is -- Adm. John Byng
This from the link:
“Byng’s execution was satirized by Voltaire in his novel Candide. In Portsmouth, Candide witnesses the execution of an officer by firing squad; and is told that ‘in this country, it is good to kill an admiral from time to time, in order to encourage the others” (Dans ce pays-ci, il est bon de tuer de temps en temps un amiral pour encourager les autres).’”
I think that’s the source of it.
(I can’t depend on my memory like I used to!)