Fan fiction generally occupies a gray area of the law - widely tolerated under "fair use" for noncommercial sharing, publication, and performance, but almost never acceptable for profiting from. This is because the original works are protected by copyright.
Despite this, there are quite a few fictional universes that have fallen into the public domain because the copyrights on the original fictional works that defined them have expired. Examples include the Cthulhu Mythos, the world of Sherlock Holmes, and Ruritania. The universes of King Arthur and the Knights of the Round Table and of Robin Hood and his Merry Men predate modern literary copyright and have likely never been protected.
From the perspective of writing, can a new work of fiction based on and set in the universe of a previous public-domain work be considered fan fiction, and how would such a work be distinguished from a non-fan fiction derivative work?
For some examples, suppose I want to write new stories set in Anthony Hope's Ruritania. Perhaps I want to do a massive multi-universe crossover where the March sisters team up with Dracula and the Mad Hatter to stop Sherlock Holmes and the Snow Queen from salvaging the wreckage of Captain Nemo's Nautilus submarine in Ruritania and using it to resurrect Cthulhu and conquer the sky city of Laputa from the Sheriff of Nottingham and the Lady of Shalott. I cannot get (or be refused) permission to fanfic from any of the authors because they are literally all dead and I wouldn't legally need that permission anyway.
To be clear, this is a conceptual question about the nature of fan fiction and not a question seeking advice on copyright.
Part of me says that yes, any attempt to do this constitutes fan fiction, but I also note that this would render literally half of Disney's film catalog as fan fiction of 18th and 19th century works. I seriously doubt that saying "Oh, Frozen is just a Snow Queen fanfic" would sparkle with them.
Alternately, is Pride and Prejudice and Zombies (2009) a commercialized fanfic taking advantage of copyright expiration to make a profit or an ordinary non-fanfic derivative literary work? Would such a distinction even have any meaning in the writing world?
For an additional example, suppose 500 years from now, the rest of the previously-exempted pre-2170 works finally enter the public domain, and a publisher bundles together some 1970's Kirk/Spock yaoi fangirl fics and publishes them. Are these stories no longer fanfic because it is now legal to commercialize unauthorized Star Trek derivative works or do they remain fanfics because they were originally intended as such?