Using the setting and characters of an existing and current book would probably, indeed almost surely, make it a derivative work. Creating a derivative work from a work protected by copyright requires permission from the copyright holder, unless an exception to copyright applies.
In US law 17 USC 101 defines a derivative work as:
A “derivative work” is a work based upon one or more preexisting works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which a work may be recast, transformed, or adapted. A work consisting of editorial revisions, annotations, elaborations, or other modifications, which, as a whole, represent an original work of authorship, is a “derivative work”.
and 17 USC 106 provides in pertinent part that:
Subject to sections 107 through 122, the owner of copyright under this title has the exclusive rights to do and to authorize any of the following: ...
- to prepare derivative works based upon the copyrighted work;
This means that creating such a fanfic without permission would be copyright infringement, and Rowling could sue for damages.
Fair use
In the US the primary exception to copyright available is fair use. Whether a work is a fair use of another is always a case-by-case decision, and often a complex one. There have not been many published US cases on whether fanfiction is or may be fair use.
This depends on the details, but from the description I do not think such a fanfic as the question describes would be likely to be held to be a case of fair use. See Is this copyright infringement? Is it fair use? What if I don't make any money off it? In general fanfiction has not fared very well under US copyright law. See this Wikipedia article.
A recent Law Review article on this topic, one of the few available, is The Better Angels of Our Fanfiction: The Need for True and Logical Precedent, 33 Hastings Comm. & Ent. L.J. 159](https://repository.uchastings.edu/hastings_comm_ent_law_journal/vol33/iss2/1) by Stacey M. Lantagne.
[Footnotes in the original shown here in {braces}.] On pages 168-9 Lantagne wrote:
Although fanfiction is a flourishing medium, there has been no
true case evaluating it under a fair use analysis. For instance, Warner Bros. Entertainment Inc. v. RDR Books 575 F.Supp.2d 513 (SDNY 2008) involved a work created by a fan, but the work in question was an encyclopedic reference book about the original copyrighted material, not a piece of fiction spun off from the original copyrighted work in some way. The fan work's inconsistently transformative character swayed the court's fair use analysis{The court noted that at times the fan work lapsed into mere verbatim copying of the original copyrighted material, which detracted from its transformative nature}, and the fact that it used more of the original copyrighted work than was necessary.{The court found it telling that the fan work contained a great deal of verbatim copying of "highly aesthetic expression," which tipped this factor away from a finding of fair use} These two factors would necessarily dictate a different analysis when a work of fiction is involved as opposed to a reference work.{Warner Bros., 575 F. Supp. 2d at 544. The court found troubling the excessive copying of "distinctive original language from the Harry Potter works," using "Rowling's original expression," in the work's entries. Id. Presumably, much less direct copying of original language would happen in a work of fiction. A similar implication occurs when considering the "verbatim copying" of whole sentences from the Harry Potter books. Id. at 547. Works of fanfiction seldom copy verbatim language, focusing on characters,
settings, and plots.}
Lantagne next discussed mthe case of Salinger v. Colting, 607 F.3d 68, 70. That case dealt with a novel called 60 Years Later: Coming Through the Rye, whose protagonist, "Mr. C", is a 76-year-old Holden Caulfield, (the protagonist of the J.D. Salinger novel The Catcher in the Rye. Lantagne wrote:
The defendant's novel embodies typical fanfiction activity: taking a recognizable character and re-imagining them at a different stage of life." The court determined that the work was not permissible fair use and enjoined its publication.{This case [on appeal] recently settled, with Colting agreeing not to publish the book in the United States or Canada until the
copyright on The Catcher in the Rye expires, but being able to publish it in other international territories, as long as it was not marketed using reference to Salinger, The Catcher in the Rye, or the litigation between the parties.}
First, the court concluded that 60 Years Later was not a parody
because it "contain[ed] no reasonably discernible rejoinder or specific criticism of any character or theme of Catcher. Rather than commenting on Holden Caulfield as a character, the purpose of 60 Years Later was to "satisfy Holden's fans' passion" for his character.
The insertion of J.D. Salinger as a character in 60 Years Later was possibly, the court conceded, a criticism and commentary of Salinger, but not of The Catcher in the Rye. While the court admitted that there was some transformative element in the Salinger character in 60 Years Later, it was limited by the character's minor role in a work that was largely not transformative. The court concluded that merely aging the main character of a novel and altering the novel's setting was not sufficient to make the use transformative. Finally, because 60 Years Later was to be sold for profit, the court found that the first factor weighed against a finding of fair use.
After finding The Catcher in the Rye to be an expressive work,
which weighed the second factor against a finding of fair use, the
court then concluded that 60 Years Later took much more from The
Catcher in the Rye than was necessary for whatever transformative
commentary it was trying to make. The court disapproved mainly of
the use of the main character of The Catcher in the Rye. 60 Years
Later also was similar to The Catcher in the Rye in structure, in a way that was not necessary to offer a commentary on Salinger (the only transformative purpose the court had found the work to have).
Finally, the court found that 60 Years Later harmed the potential market for any permissible The Catcher in the Rye sequels. The court found that fair use should not protect the ability to publish unauthorized sequels:
[B]ecause some artists may be further incentivized to create
original works due to the availability of the right not to
produce any sequels. This might be the case if, for instance,
an author's artistic vision includes leaving certain portions or
aspects of his character's story to the varied imaginations of
his readers, or if he hopes that his readers will engage in discussion and speculation as to what happened subsequently."
Although 60 Years Later may be classified as fanfiction, the
overtly commercial purpose of the work makes it an imperfect
representation of the genre because most fanfiction is not-for-profit.{See Tushnet, supra note 16, at 664. A recent development in fanfiction that has led to clashes is the rise of the use of fanfiction for charitable purposes. "Fanfic auctions" in which readers bid for the services of fanfiction authors to write a story based on their specifications, with the proceeds to benefit charity, are becoming more common. See Gabaldon, supra note 7 ("Recently, a couple of people have drawn my attention to a
person who's been posting on various boards about fund-raising for an uninsured friend named Stacie who has breast cancer. Her (the poster's) idea for fund-raising is to auction off a customer-written piece of fan-fic. . . ."). Fanfiction written for such a commercial purpose may change the analysis. But see Tushnet, supra note 16, at 672-73 (quoting
Gene Rodenberry).} Because the court weighed the novel's commercial nature against a finding of fair use, Salinger is not an ideal fanfiction precedent
Lantagne goes on to discuss the case of Suntrust Bank v. Houghton
Mifflin Co 268 F.3d 1257, 1259 (11th Cir. 2001). In that case a novel The Wind Done Gone, retelling Gone With the Wind from the PoV of the black characters, was held to be a parody as well as a sequel, to be "highly transformative", and allowable as fair use.
Sequels as Derivative Works
A sequel uses the characters and/or setting of an existing work of fiction. It often constitutes a derivative work. The more distinctive and original the setting and characters are, and the more of those distinctive characteristics that are used in the sequel, the more likely the sequel is to be treated as a derivative work.
On the matter of sequels, see the case of Anderson v. Stallone, 11 U.S.P.Q.2d 1161 (C.D. Cal. 1989). In that case, a Mr. Timothy Anderson prepared a sequel to the film Rocky III which he hoped would become Rocky IV. He presented it to MGM and Stallone. They eventually declined to buy it, and Anderson sued, claiming that the film Rocky IV that was made infringed his script. The district court held that Anderson's script was an infringing work not entitled to copyright protection. The court, citing Nichols v. Universal Pictures Corp.. 45 F.2d 119 (2d Cir. 1930), ruled that the characters in a copyrighted work are protected when they are "developed with enough specificity to constitute protect able expression." Holding that the Rocky III characters met this standard, the court ruled that the Anderson script was a derivative work created without permission, and thus was not entailed to any copyright protection at all. Anderson appealed, and the case was settled out of court while this appeal was in progress. Details of the settlement were not disclosed.
An unauthorized sequel to Harry Potter would probably face the same rule and reach the same result as in the Anderson case.It would depend on how much of the "distinctive" nature of JKR's characters and settings were used in the fanfic sequel.
The Ethical and Emotional Arguments against Fan Fiction
In This comment on the question user "RedSonja" writes:
I know this is Law and you are looking for legal answers. But what you are proposing is plagiarism by the back door. JKR went to a lot of trouble inventing her universe. Why should you be able to just plug in and milk someone else's cow? If you are that highly original, write your own universe.
Leaving aside the point that if the source is acknowledged it cannot be plagiarism, although it may be copyright infringement, this is essentially an ethical argument that the law should be different than it currently is. Some authors make an essentially emotional argument, saying that their works or their characters are in effect "children of the mind" and that others should not touch them without permission, whatever the law may say. Some find such arguments persuasive or powerful.. I disagree with these arguments.
Lantagne on pages 172-179 of the law review article linked above, responds to such arguments, writing [Some footnotes omitted, others in {braces}]:
Fanfiction is frequently devalued as not being "real" writing.
This is closely related to the aesthetic argument. Copyright only
protects creative expression.{See Eldred v. Ashcroft, 537 U.S. 186, 219 (2002)} If the fanfiction is not creative
expression, then it is not copyrightable. That, however, is a different question from whether it is infringing.{See Tushnet, supra note 16, at 681 ("Fan fiction may not be copyrightable, but
that does not make it an infringing use....").} It could be that the "not real writing" argument, translated into legalese, really expresses the idea that the work of fanfiction is not transformative enough.{See Campbell v. Acuff-Rose Music, 510 U.S. 569, 580 (1994) ("If, on the contrary, the commentary has no critical bearing on the substance or style of the original composition, which the alleged infringer merely uses to get attention or to avoid the drudgery in working up something fresh, the claim to fairness in borrowing from another's work diminishes accordingly (if it does not vanish), and other factors, like the extent of its commerciality, loom larger."). Importantly, however, a work does not have to be transformative to be protected under fair use. See id. at 579. The fair use test is not forgiving of shortcuts.} However, this alone does not automatically make the work a copyright infringement because other fair use factors remain.
Many authors frequently describe fanfiction as being the
equivalent of an affront against their relatives.{See Gabaldon, supra note 7 ("[L]et us just say that there's a difference between
someone dating red-haired men, and the same someone trying to seduce my husband.... I wouldn't like people writing sex fantasies for public consumption about me or members of my family-why would I be all right with them doing it to the intimate creations of my
imagination and personality?"); Someone Is Angry on the Internet, supra note 11 ("My characters are my children, I have been heard to say. I don't want people making off with them, thank you."); Hobb, supra note 7 (comparing fanfiction to PhotoShopping a family
photo).} While the artistic protectiveness for one's creation is understandable, it is not a valid argument in U.S. copyright law. Artists have the right to control derivative works of their creations. If the fair use factors come out the wrong way [for the reuser], artists can prevent that use of their work. However, the purpose of copyright is not to prevent all use by others of an artistic work.{See, e.g., Campbell, 510 U.S. at 574-77 ("From the infancy of copyright protection, some opportunity for fair use of copyrighted materials has been thought necessary to fulfill copyright's very purpose ...)} It never has been. The very character of the fair use test illustrates this, as it protects most strongly those uses of an artist's creation that the artist would never permit.{See Suntrust Bank v. Houghton Mifflin Co., 268 F.3d 1257, 1282-83 (11th Cir.2001) (Marcus, J., concurring) ("To the extent the Suntrust [sought to impose editorial restrictions] to preserve Gone With the Wind's reputation, or protect its story from 'taint,'
however, it may not now invoke copyright to further that goal. Of course, Suntrust can choose to license its derivative however it wishes and insist that those derivatives remain free of content it deems disreputable. Suntrust may be vigilant of Gone With the Wind's
public image-but it may not use copyright to shield Gone With the Wind from unwelcome comment, a policy that would extend intellectual property protection 'into the precincts of censorship,' in Pat Conroy's words.")} Arguably, the more that a fanfiction work criticizes or parodies the original work, the more that fanfiction is a fair use. Thus, the argument that fanfiction should not be permitted because it transforms the original authors' characters mirrors the argument for exactly why fanfiction should be permitted under copyright law.
...
The arguments that authors advance when they argue against
copyright belong in a regime without fair use-a regime that would
ignore the central purpose of U.S. copyright."' Such a conclusion is
not only potentially untenable under the Constitution, but is also
undesirable."' "The public's interest in free expression . . . is
significant."" There is no question that courts have, throughout the
history of copyright law, sought to protect that public interest.
However, there is also no question that courts are inevitably
swayed by value arguments. This should not be the case, but such
influence is inevitable. ' Furthermore, value is a chicken-and-egg
argument: Campbell did not base its decision on the popularity of
music sampling, but surely the popularity informed Campbell's
understanding of the critical commentary value of "Pretty Woman."
...
[T]he use of the word "fair" in "fair use" does not mean that
it is fair to the author's wishes. Rather, it means that it is fair to the purposes of copyright.
None of the emotional arguments frequently raised against
fanfiction support a blanket proclamation that none of it is fair use. Truthfully, much of fanfiction may very well not be fair use.
However, a true test case of fanfiction, logically evaluating each
factor, would be invaluable in moving the fanfiction debate past the
emotions of the participants. The argument should focus not on the
emotions of the author or the quality of the writing, but on the fair use factors: on the purpose, character, and possible transformative nature of the work, on the amount of the original copyrighted work used, on the nature of the original copyrighted work, and on the effect on the market of the original copyrighted work. These are the factors that best protect the advancement of the twin goals of U.S. copyright.
I agree with Lantagne here, it is often exactly those uses that a copyright owner will not want to approve that should be permitted as an exception to copyright. The limited statutory monopoly is granted in return for a contribution to the clutural fabric, and such work should therefore be available for use in further developing that fabric where it does not deprive the copyright holder of financial rewards, and where such uses in general are of public benefit. I take it thatr current US copyright law follows that goal, more or less.
Non-US Law
The rule on derivative works is also contained in the Berne Copyright Convention and the WTO's TRIPPS Agreement, and so applies in almost every country. Exceptions to copyright, however, vary widely. The concept of Fair Use is originally a purely US concept, although it has been adopted by Israel, and in part by a few other countries.
Other countries generally have more specific and narrower exceptions, but often have several different exceptions. India has some 28 different exceptions in its copyright law. Few of these seem likely to be any more favorable to a fanfiction sequel than the US concept of fair use.