Learning to write can only be described as a process of trial and error. For every polished piece or story that is published, there are others that are still in messy draft form.
Many writers (myself included) started writing via fanfiction. Fanfiction is fiction that is based on previously released work. The beauty of this genre is that there are so many opportunities to take the narrative in a new direction. The story can be a prequel, a sequel, go inside a character’s head, take place in an alternative universe, etc.
The one caveat is that the publishing date determines whether or not the writer is breaking copyright laws. Anything that was published more than 100 years ago (i.e. the novels of Jane Austen or Charles Dickens) is public domain and obviously fair game. The same cannot be said if the tale being crafted is based on a work that is less than a century old. Anyone writing, for example, Harry Potter or Star Wars fanfiction is wading into legally murky waters.
The answer is yes, you can learn to write via fanfiction. Some of my early works are in need of a major rewrite. Even with that cringe factor, there is no doubt that I was learning along the way. The basics of creating fiction in terms of narrative, characters, setting, etc, can be mastered via this genre. E.L. James, the creator of the Fifty Shades of Grey series, has become one of the preeminent authors of our era started out by creating Twilight fanfiction. Regardless of one’s opinion of James’s writing, there is no doubt that she has turned a hobby into a successful career.
Not everyone takes the same route when they start out writing. That does mean, however, that one path is better or worse than another. We all learn how to craft stories in our own way and own time. One of these routes is fanfiction.