Let's face it: When we start out, nobody knows how to write. Each of us has to find a way. Each writer has to be self-educated.
So at the outset there's a strong inclination...to copy. Writers who like Stephen King want to write like Stephen King. Writers who admire J.K. Rowling would love to write like her. Those who enjoy Neil Gaiman's work want to impress the girls the way he does...by writing like him, of course.
But isn't there some rule, "Thou shalt not steal," or something?
Yes, there is. But writers learn to write by writing, and they learn their first elements of style from imitation. Robert Louis Stevenson wrote that when he was an aspiring writer, he became a "sedulous ape," industriously trying to copy the styles and characters of writers he admired, including Sir Walter Scott.
However, Stevenson says, what he wrote "was for no ulterior use, it was written consciously for practice. It was not so much that I wished to be an author (though I wished that too) as I had vowed that I would learn to write."
Stevenson succeeded in becoming one of the most successful novelists of the late nineteenth century. And people still read and enjoy his books.
Now, some of us like the work of an author so much that we just can't keep our sticky little hands off their characters. So we write fan fiction, and possibly even publish it on the Internet.
The trouble begins here. To protect their copyright, writers have to draw a line, and that line does not permit direct stealing of characters, situations, and settings.
Not that there's anything wrong with writing fan fiction. It's the publishing that gets copycats in trouble, and especially if the publication is commercial, i.e., for money.
Unless you change things pretty drastically so there's no longer a clear connection between the original material and your own work. That can be done. Ethics are not always black and white, and there are shades of gray.
However: I do recommend that you steer clear of writing continuations of works you enjoy and publishing them, even if it's not for profit.
It is perfectly okay to mimic a technique, style, an effect, an atmosphere, or a mood, though. That's how you learn to write. Eventually you develop your own individual style.
Ah, style...but that's a topic for another time.