Fictional writers often have to create (or imagine) the events and people they want to portray in their books from nothing. They will use some influence or inspiration from real-world events and people, but they often create a person or events that are completely fictional.
With Fantasy and Science Fiction writing, it is considerably more involved. In order to create a world as rich as that found in the Dungeons & Dragons novels, the Chronicles of Narnia, Star Wars, DUNE, Harry Potter, etc, they will (in 99% of the time) create the entire world, every galaxy, star, planet, continent, island, right down to the blade of grass.
They will literally create everything from political alliances and shifts to the history that led the world they created to its point in time in the story they want to write for their readers.
Once complete, they have a world that is every bit as detailed as the real world. With all of this written down, drawn out, and so on, they literally have everything documented so that, after they have written down their tenth novel of the series, they can remain true to the original intentions of the story. There will not be any contradictions or mistakes or things overlooked because the story itself is all rooted from the same "facts" that the writer created in the first place.