A pronoun's case is determined by its function in a sentence, but sometimes a pronoun's function is confusing because it is part of a clause or phrase that is embedded in another clause or phrase, as in this sentence: Give the leftovers to (whoever, whomever) wants them. In this example, the pronoun is the subject of the clause "whoever wants them," and as the subject of the clause, it must be in the nominative (subject) case ("whoever").
However, the entire clause ("whoever wants them") is a noun clause acting as the object of the preposition "to." The fact that the preposition appears right next to the pronoun causes many people to assume that the pronoun is the object of the preposition and therefore should be in the objective case. But the pronoun is not itself the object of the preposition; rather, the entire noun clause is.
When a phrase and a clause compete to determine the case of a pronoun, the clause always wins. Just think of a clause as a "stronger" grammatical structure, even if it is embedded in a phrase, as in the example above. Thus, the fact that the clause needs its subject causes "whoever" to be in the nominative (subject) case, even though the phrase wants an object.
Here is another example of the way a clause trumps a phrase when it comes to determining the case of a pronoun: "They wanted me to read them a story." In this sentence, the pronoun "me" is actually the subject of the infinitive phrase "me to read them a story," and that entire phrase is the direct object of the verb "wanted":
What did they want? They wanted me to read them a story.
The "who, whom" issue is more complicated, because so many people are intimidated by the form "whom" that they assume it must be the "more educated" version of the pronoun. I often hear or read such sentences as this one: "Although he will consult his advisors, it is the candidate whom must make the final decision." Since the pronoun is the subject of the clause, however, it must be in the nominative case ("who"), not the objective case ("whom"). Corrected, the sentence reads, "Although he will consult his advisors, it is the candidate who must make the final decision."
I found this error in a Time Magazine article on the Gores: "She had just begun to realize whom it was she had married."
The corrected version would read, "She had just begun to realize who it was she had married," because "who" is the subject complement of the clause "it was who," and therefore must take the same case as the subject (the subjective case).
Here's one that might give you pause: "All things come to (he, him) who waits." Because the pronoun is the object of the preposition "to," it should be in the objective case: "All things come to him who waits." The subject of the adjective (relative) clause "who waits" is "who," but "him" is not the subject of that clause--it is simply a pronoun that is modified by that clause. Its case is determined by the fact that it is the object of a preposition: All things come to him. The rest of the sentence is an "add-on," and it does not affect the case of the pronoun "him" used as the object of the preposition "to."
In the movie Pretty Baby, which came out in the 1980's, a prostitute says of a rich, elderly client, "He can have whatever he wants, but what he wants is me, who cares nothing for him." I remember that sentence well because of the grammatical arguments it provoked. The sentence should actually be, "He can have anything he wants, but what he wants is I, who care nothing for him."
Of course, the character is not an educated woman, so there would be no reason for her to express herself that way. (To be quite honest, I don't think anyone should construct such a sentence. Its correct form sounds really weird, but its more natural-sounding form has too many errors in it. )
The reason why the first person pronoun must be "I" rather than "me" is that it is the subject complement of the clause that it occurs in, and subject complements must always be in the nominative (subject) case, because they serve to rename or identify the subject of the clause.
That's why you're supposed to say, "It is I," or "This is she," although in colloquial speech hardly anyone ever does. Though I consider the sentence under discussion to be rather goofy, it does offer the opportunity to examine why certain pronouns have to do certain things in a sentence.
The subject of that first clause is "he," and "what" is the direct object of the verb "wants" ("he wants what"), although the order is inverted as it would be in a question. The entire clause "what he wants" is a noun clause acting as the subject of the verb "is." Thus, we have the structure "X is Y." In that structure, the word following the linking (state of being) verb will be a subject complement, either an adjective (predicate adjective)or a noun or noun substitute (predicatenominative). If the predicate nominative is a pronoun, it must be in the nominative case--i.e., "I."
Now, about that verb "care." The relative pronoun in a relative clause (in this case, "who") takes the same number and same verb form as the noun or pronoun it refers to. Since "I" would take the form "care" rather than "cares," the "who" that refers to "I" also takes that form, thus requiring "who care," rather than "who cares": What he wants is I, who care nothing for him.