Although comments above point to earlier examples (e.g., Les Diaboliques and The Mousetrap), I would argue that the "spoiler" first became a modern phenomenon, at least in American popular culture, with the Alfred Hitchcock's famous advertisements surrounding his 1960 film Psycho. The unexpected murder of Janet Leigh's character, and of course the final reveal of the murderer's alternate personality, were protected with a famous anti-spoiler marketing strategy.
You can see this anti-spoiler marketing in this short doc: https://youtu.be/DjRzj_Ufiew
These strategies included:
- Not allowing latecomers into the theater
- A tag line in theaters that read: "If you can’t keep a secret, please stay away from people after you see Psycho."
- Print advertising that encouraged viewers from not revealing the ending.
- Hitchcock personally buying all remaining copies of Robert Bloch's novel Psycho.
If you're looking for any specific works on the history of spoiler-aversion, I'd recommend C. Namwali Serpell's Seven Modes of Uncertainty, specifically the second chapter, "Enfolding." The chapter offers a nice review of the thought around spoiler aversion, and the second footnote there has this:
Alfred Hitchcock's Psycho (1960) did a lot to get the idea of spoilers off the ground. His stringent restrictions on the revelation of the film's secret twists were advertised widely, and for the first time in film history, audiences weren't allowed to come into the theater after the movie began. "It is required that you see Psycho from the very beginning," read posters depicting a comically stern Hitchcock tapping his watch. Hitchcock was probably inspired to develop these techniques because of Henri-Georges Clouzot's Les Diaboliques (1955), the end of which included an "anti-spoiler" message. A decade later, Doug Kenney wrote a piece for National Lampoon called "Spoilers," which revealed the plots of famous films. (330-331)
Namwali Serpell's chapter goes on to focus on the spoiler in literature, specifically Ian McEwan's 2001 novel, Atonement, as it relates to the literary mode of uncertainty he terms enfolding.