"Whoever" would be correct. The blank in your sentence is not the object of "gave". The entire clause "___ deserved it most" is the object of "gave", which in turn means you'll use "whoever", which is the subject of "deserved".
The rule here is exactly like what you said: who = subject, whom = object. The trick in this case is understanding the clauses in this sentence.
The Wikipedia link about the accusative case explains that
Modern English, which almost entirely lacks declension in its nouns,
does not have an explicitly marked accusative case even in the
pronouns. Such forms as whom, them, and her derive rather from the old
Germanic dative forms, of which the -m and -r endings are
characteristic.
Now, whether to use who or whom in your sentence entirely depends on which case should be used, accusative (whom) or nominative (who).
In English, it is grammatically correct to use nominative after the verb to be as in
It's he who stole my car. It's they who told me the truth. It's she
who lied to me.
However, we know that "It's me" (using the accusative case after to be) is broadly used in English. But it is just a few exceptions.
In your sentence, it is appropriate to use the nominative case as it is the complement of to be. If you divide the sentence into two parts:
He must decide / He should be who => He must ask who he should be => He must decide who to be.
in the same way as:
He must decide / He should meet whom => He must decide whom he should meet => He must decide whom to meet.
He must ask / She is who => He must ask who she is. (This question cannot be shortened with wh-word + to-infinitive as the subjects are not same.)
We don't ask,
*Whom is he? or *Who is him?
*Whom am I? or *Who am me?
because whom and him/me are the accusative case and can't be a complement of the verb be in this case.
Note: "He must decide who he wants to be" is more idiomatic than "he must decide who to be".
Best Answer
This answer is based in large parts on the comments to a deleted question, “I am who/whom he loves”: BillJ in particular was very helpful.
"Whom" would be correct here. As in most cases, "who" is also acceptable here.
Edwin Ashworth's commented that neither sounds very good, and suggested " 'They are the people we dislike.' This seems to be because in English, the pronouns who and whom cannot normally be used as fused relative pronouns (Cognitive English Grammar, by Günter Radden, René Dirven).
However, the sentence is grammatical if it is interpreted as the answer to a question "Whom do you dislike?" In other words, the pronoun is not being used as a fused relative pronoun, but as an "interrogative subordinator."
BillJ explains the grammar of the analogous sentence "“I am whom he loves":
--