Here's a link that has a list of legal cases that would be important precedents for US fan fiction authors should familiarize themselves with.
And the Number 4 case in that list would answer the question regarding Rowling and the fan fiction author, at least in this country.
Put another way, you can't infringe something that infringed you first.
I pay attention to this simply because the first major work of mine that I posted here on SOL is a fan fiction of the Bethesda game The Elder Scrolls V: Skyrim. In my case, there are two things that would indicate that Bethesda, who owns the copyright, won't bother me. First, Bethesda actively allows players of the game to make mods for the game, things that can actively change the way the game is played, change the storyline, even to the point of players adding mods that bring in elements of OTHER Bethesda games, AND they allow those mods to be freely distributed to other players. And second, I'm not trying to make a profit of my story.
If I were to try to make a profit off it, then I would do what Erika Mitchell (aka E.L. James) did and change enough of the book such that, while it would still have some of the common elements of Skyrim that pretty much are standard fantasy stories now (Elves, Dragons, magic, etc.), they would no longer infringe upon any copyright held by Bethesda. Fifty Shades of Solitude, maybe? :)