There are two basic theories here. The first is that the crowd misheard Jesus. The second is that they purposefully twisted his words to mock him. Commentators are fairly evenly split on which option is more probable.
In the first view, the crowd was at a significant enough distance that they could not hear Jesus clearly. Additionally, those in the crowd may have been poorly educated and/or Hellenists and therefore did not have a strong command over the Hebrew. Thus when Jesus said "Eloi" they heard "Eli" which their brains interpreted as "Elias" (=Elijah). In support of how this would be an easy mistake to make, Ellicott's Commentary cites Matthew 16:14 and Matthew 17:10 which show that it was a common expectation during Jesus' time that Elijah would return at the coming of the Messiah (in reference to Malachi 4:5).
The dominant expectation of the coming of Elijah would predispose men to fasten on the similarity of sound, and the strange unearthly darkness would intensify the feeling that looked for a supernatural manifestation of His presence.
The other option is that the crowd heard Jesus alright but seized on the opportunity to mock Jesus. In this view, the crowd was referencing the same Messianic prophecy (Malachi 4:5), but were essentially saying "even Jesus realizes the prophecy was not fulfilled." Barnes' Notes writes:
The taunt would be more cutting, because it was the universal belief of the Jews, as well as the doctrine of Christ, that "Elias" would come before the Messiah. They derided him now, as calling upon "Elias" when God would not help him; still keeping up the pretensions to being the Messiah, and invoking "Elijah" to come from the dead to aid him.
In my view, a simple misunderstanding is more likely. In Matthew, the episode continues:
And some of the bystanders, hearing it, said, “This man is calling Elijah.” And one of them at once ran and took a sponge, filled it with sour wine, and put it on a reed and gave it to him to drink. But the others said, “Wait, let us see whether Elijah will come to save him.” (Matthew 27:47-49, ESV)
It seems that the man offering up the sponge probably heard Jesus correctly and understood He was suffering and tried to help. The statement by the rest to "wait and see" could be read as further mocking, but to me more naturally suggests a initial misunderstanding, followed by doubt that Elijah would actually come without fully ruling out the possibility.
As the Pulpit Commentary points out, the fact that the insult theory relies on a Jewish audience purposefully distorting the name of God also creates a significant difficulty:
The time of ribaldry and abuse is now past; the supernatural darkness has had a calming and terrifying effect; and there is no spirit of mockery left in the awed bystanders. Besides this, it is not likely that Jews, who with all their errors and vices paid an outward respect to holy things, would have presumed to make a play on the sacred name of God.