In order to answer the question, I will make comments on the passage in small portions.
QUOTE: Mark 9:11 And they asked him, saying, Why say the scribes that Elias must first come?
The inner three disciples (Peter, John, and James) are coming down from the Mount of Transfiguration where they have seen the glory of the Lord. Jesus told them not to tell others about this until after He had risen from the dead. They discuss this among themselves and are puzzled over the meaning of the resurrection from the dead. In their confusion, they ask about the common teaching that Elijah (Elias) will come before the establishment of the kingdom by Messiah.
QUOTE: Mark 9:12 And he answered and told them, Elias verily cometh first, and restoreth all things;
Jesus agreed that Elijah must come first and restore all things. This is taken from the teaching of Malachi 4:5-6, the last two verses of the Old Testament in our Bibles today, which state: "Behold, I will send you Elijah the prophet before the coming of the great and dreadful day of the LORD: And he shall turn the heart of the fathers to the children, and the heart of the children to their fathers, lest I come and smite the earth with a curse."
QUOTE: and how it is written of the Son of man, that he must suffer many things, and be set at nought.
Jesus then adds that it is written that the Son of man must suffer many things and be set at nought. This refers to passages such as Psalm 22 and Isaiah 53. They teach of the suffering Saviour who will come. Jesus identifies Himself as this man. This statement seems to be strangely added. They were asking about Elijah not about the Messiah suffering. But it is appropriate because the conversation began with their confusion over the meaning of the resurrection. He is trying to bring them back to the real point. He will be killed and then be resurrected the third day.
QUOTE: Mark 9:13 But I say unto you, That Elias is indeed come,
This refers to John the Baptist. He came "in the spirit and power of Elias" (Luke 1:17). Of him, Christ said, "For all the prophets and the law prophesied until John. And if ye will receive it, this is Elias, which was for to come" (Matthew 11:13-14). That is, if the Jewish people had accepted Christ as king, John the Baptist could have fulfilled the prophecy concerning Elijah. But they did not accept him, so Elijah's coming is still future.
QUOTE: and they have done unto him whatsoever they listed,
The Jewish leaders not only rejected John, but they have done unto him whatever they "listed." That is, they did whatever they desired or wished to do. The word, list, is related to the word lust. It means that they simply followed their base inclinations. We see this in the imprisonment and subsequent beheading of John.
QUOTE: as it is written of him.
This phrase goes back to the previous verse where it refers to the things that are written of the sufferings of the Son of man. Jesus is trying to explain to His inner circle about His coming sufferings. He explains that the Jews have rejected their potential Elijah, persecuted him, and even killed him. In fact, they have basically done the things to John that the scriptures teach will be done to Jesus Christ. The "him" of "as it is written of him" refers, not to John, but to Jesus Christ. They have done whatever they listed to do to John as it is written that they will do to the Son of man. Jesus is trying to reveal to His disciples the kind of rejection that He will soon receive and the reason He will need to be resurrected in order to fulfill His calling as Messiah.