Mark 9:13 But I tell you that Elijah has come, and they did to him whatever they pleased, as it is written of him.
Here is an excerpt from an online commentary [The Believers' Bible Commentary] which has a good explanation of this passage:
Mark 9:12, 13 Jesus answered in effect, "Indeed, it is true that Elijah must come first. But a more important and immediate question is this: ‘Don't the OT Scriptures predict that the Son of Man is to endure great sufferings and be treated with contempt?’ As far as Elijah is concerned, Elijah did come (in the person and ministry of John the Baptist), but men treated him exactly as they wanted to—just as men treated Elijah. The death of John the Baptist was an advance token of what they would do to the Son of Man. They rejected the forerunner; they will reject the King."
I hope you have found this helpful.
God bless,
Mike