Copyright laws don't last forever. I believe it's somewhere between 50 or 75 years after the author's death, or something like that-- I used to know this but I forgot.
For example, Gregory McGuire, who wrote "Wicked" (based on the Wizard of Oz characters) had to wait a certain amount of time for the copyright on the characters to expire before he could publish his books.
There is also a sequel to Phantom of the Opera that the author waited for the copyright to run out on.
I expect in 100 years or so, if people are still interested in Harry Potter and the Wizarding world JK Rowling created, they will be writing about them again, free from copyright infringement.
The copyright is to protect your work from being used by others, but there are certain figures in legends and mythology that no one holds the copyright on because they are so old or no one knows their origins.