I'm writing a literary analysis piece on Shirley Jackson's The Haunting of Hill House. Online, such analyses are often preceded by a warning that the contents of the page contains detailed information about the plot so that someone who hasn't read the book yet would know not to read it if they don't want the plot spoiled. Does such a "spoiler warning" have a place in a formal essay? The format of the essay is MLA.
If by 'formal' you mean that your essay will be academically assessed or published, then it would be inappropriate to include a spoiler warning. That would literally make your piece look amateurish.
Spoiler warnings are suitably considerate in the perfectly legitimate realm where enthusiasts discuss a text and people primarily hope to enjoy the plot. When I am chatting about a text in the pub, I am speaking in this way as an amateur or enthusiast, and I strive not to reveal plot points.
When writing academically-orientated material, however, that would not be an appropriate consideration. I would look amateurishly clumsy if I were to write about Hamlet while coyly skirting the fact that (almost) everyone dies by the end. I expect readers to be familiar with the text we are discussing. If their primary concern is enjoying the plot, then they have simply selected an inappropriate piece to read.
We can all write as both enthusiasts/fans and academics, depending on circumstances. The two types of material work differently.
"Does such a "spoiler warning" have a place in a formal essay?"
It is courteous and considerate of you to ask this question, but unless you plan to informally publish your essay (online, for instance), you may assume that your reader has already read the book and that no "spoiler alert" is required. In short, such an alert would be inappropriate in a formal essay.