First, notice that there's actually nothing inherently wrong with the grammar of "What is me?"
It appears without raising any red flags in at least two contexts:
— "I have a body, I have a mind... but what is me? Is it my thoughts? My will? My two hands?"
— "Why, your soul is you."
— "But, Father, how do I know that I have one at all?"
Notice that the answer to "What is me?" isn't "You are X," as it would be if the question were instead "What am I?" Instead, it's "X is you."
It can also appear a context where a wh- question replaces a previously stated subject in a declarative sentence without any syntactic movement:
— "Look, over there! That's a lion!"
— "What's a lion? I don't see anything!"
More importantly, there are many sorts of questions in which "what" refers to the subject of the verb, not the predicate:
What's up?
What's moving on the horizon?
What has two arms and four legs?
Therefore, here's what I find interesting in your question. Yes, it's correct to say that "What is me?" at the end of a riddle should be "What am I?" if "what" is the predicate of the copula, whose subject is "me" and hence should be in subjective case "I": "What am I?"
But what if we don't take that parsing for granted? That is, here's how I read the core of your question: Why, in riddle format, can't "me" be the predicate for a subjective "what"?
So we must add to our analysis.
We can start by noting the unusual behaviour when this sort of question is completed by a noun or pronoun.
Here is a sentence in which the subject is unambiguously inverted:
What are those things on the horizon?
"Those things" must be the subject given the conjugation "are". I have a strong reaction to the malformed question "What is those things on the horizon?"
But here's another sentence that, imagining that we didn't know the above, is ambiguous on the surface. Is the subject inverted or not?
What is that thing over there?
A patient examination will reveal that there are two possible ways to answer this question. The first analyzes "that thing" as the subject and "what" as the predicate:
That thing over there is an elephant.
The second way suggests that the true subject was "what":
"An elephant is that thing over there."
Bear with me as I examine that declarative sentence on its own merits, without reference to the question that produced it. "An elephant is that thing over there." This certainly is odd; but why?
A speaker might read it and assume that a poetic inversion has been made, a rather bold one, and that "an elephant" belongs at the end, as we saw before. All right, fair enough.
But another speaker might recognize this as another pragmatic format: definition.
Reading it that way, the sentence would be trying to tell us about elephants. That is, "An elephant is that thing over there" could have the same structure as "An elephant is a large mammal."
But this second definition strikes us as much better. And it seems to be because in the definition format, you can't cite a particular object, "that thing over there," for your definition. This can be seen even if we try a less vague object: "An elephant is this mammal here" doesn't work either.
Interestingly enough, when defining a term, as if it were an idealized Platonic form, it seems you can't use a particular object. You can even be grammatically definite, so long as you include some kind of predication or assignment over a set, not an individual creature: "An elephant is that big grey animal you see at the zoo."
Moreover, you can't have a particular thing on the left-hand side either and have it still be a definition. If I say "The elephant is a large mammal," either (a) "The elephant" means "An elephant" or "All elephants" anyway, or else (b) it's providing some information about a particular elephant (as if you were saying "The elephant is a baby").
All the above rules out such sentences as "An elephant is me," but we aren't done just yet!
There is another similar pragmatic format: identification. It's similar in structure, but the roles are filled differently. This time, you must have a particular object on the left-hand side.
Here's an example:
— "Six people killed in one month! Who can the murderer be?"
— "I've got bad news for you. The murderer... is me!"
Observe that if the thing on the left is not definite, the form becomes entirely ungrammatical:
A murderer is me!
However, you can have something indefinite on the right-hand side:
We've ascertained that the murderer is an escaped convict.
To take another example, you can also have a demonstrative pronoun on the left side:
— "Look at this old photo, Darlene. I've figured out who everyone is except that person there."
— "Who, that? That's me!"
(In fact, to broaden the topic for a second, another person could look over their shoulders and say, "Hey, I was there that day. Boy, all the faces are so dark. Who's me in this photo?")
Or to cite a James Ward song: "But there's one hope that keeps me alive, a hope that's clear and true. That hope... is you!"
Now, it seems to me that this latter form is the one in play in a riddle. We are trying to identify the thing alluded to.
If we slot this into the above identification form, we clearly see that it's just the same problem we encountered with "murderer": the left-hand side is not one particular thing.
An elephant is me!
This sentence is therefore impossible. But we may reverse it and satisfy the requirements of the format:
I am an elephant!
Now the left-hand side is definite and particular, while the right-hand side is indefinite. We saw that this was okay above with "The murderer is an escaped convict."
So my theory about this question is that the meaning is incorrect, not the grammar. Like other wh- questions, "what" is in limbo. It must be some particular thing, so it can't be on the left-hand side of a definition. But you don't know what you're referring to yet, so it can't be the left-hand side of an identification. And those are the formats that seem to be available for the last line of the riddle.
It's a difficult subject to feel one's way through. But that's because more than grammar is involved. Yes, there is a grammatical account of your sentence; the problem is that there are two. The question was why one of them is invalid in the context. That means it does need both parsing and interpretation, in the semantic sense.