How's this for a lousy analogy?
I've heard of giant squids. People have told me that they're out there. I however have never seen one in person (in squid?), so I can't truly know that they exist.
Never mind; that really was lousy.
The legality lies in the fact that fanfiction makes use of an author's intellectual property. To use Jim's characters, settings, and so forth could therefore be seen as a sort of plagiarism. If an author visits a fanfiction site and doesn't push to have references to his or work removed, the site's owner could say that the author has tacitly endorsed the site.
And as others have stated, suppose I write a story in which Harry does X. Suppose Jim in a future novel has Harry do X, or an X-like thing. I then get all irate and sue Jim for stealing my idea. Jim's best argument against that is that he's never been to the site where I posted my story.