If fanfiction is legitimate, wouldn’t that also mean that publishers or studios could produce derivative works without compensating the original authors?

No. Profit matters, and the degree of transformative quality matters: telling stories around a campfire, freely sharing nonprofit fanfiction, summarizing plot in a book review, or making a documentary film about fans is not the same as a major commercial derivative enterprise like making a major TV miniseries out of a novel.