The whole thing is a setup. First God sends his messenger (angel) to set Elijah on a journey to the holy mountain, Horeb (an alternate name for Mount Sinai, where Moses received the Law), and to feed him a meal to fortify him for the journey. Then when Elijah gets there, God feigns surprise: “What are you doing here, Elijah?” What brings you here? Just as with Cain, God asks a question to which he already knows the answer.
Now God puts on his little show with the wind and the earthquake and the fire, and finally the “still, small voice” which asks him again, “What are you here for, Elijah?” Elijah hides his face in his mantle (’eder), the same mantle that, at God’s command, he will go on to bestow on his disciple, Elisha. (This, incidentally, is where we get the English idiom of the successor “assuming the mantle” of his predecessor.)
I don’t read it as a punishment of Elijah, though, but just a recognition that his work is nearing its end and it’s time to “pass the mantle.” Indeed, when Elijah’s time comes, he doesn’t die but is taken up into heaven alive in a fiery chariot [2 Kings 2:11]: one of two figures in the Hebrew bible whose death is never reported. (The other is Adam’s great-great-great-great-grandson Enoch, who doesn’t die but “walked with God and was not, for God took him” [Genesis 5:24].) This is the origin of the belief that Elijah is still alive somewhere, and thus able to visit every Jewish home on the night of the Passover seder.