Maybe it’s a subordinate clause lesson, because that’s the key here.
From the June 2021 Scientific American, page 62:
In Lisbon, Portugal, the social centers Disgraça and RDA69,
which strive to re-create community life in an otherwise highly
fragmented urban situation, reached out with free or cheap food
to whoever needed it.
https://www.scientificamerican.com/index.cfm/_api/render/file/?method=inline&fileID=5F31A1C3-AF1A-4CF0-A00D504B5F075088 (probably a paywall)
Last line. Shouldn’t that be “to whomever…”? After all, “to” is a preposition, so we should use the objective case, right? Nope.
Here’s the rule:
Go from the inside to the outside.
What’s inside the prepositional phrase? A noun clause! And “who” (well, “whoever”) is the subject of “needed,” so it gets the nominative case!
So there you have it. Sometimes you can say “to who.”