A favorite anecdote, and I don't know anything, I could have misheard it, was about Tolkien.
Apparently, he did not know the character Saruman existed. He was just working the story, and had this gap which eventually turned into Saruman. Saruman seems rather "important", so it's interesting (to me) that it was not a core character from early on.
As a non-writer, even as a programmer, I find it kind of surprising that the authors surprise themselves. Writing code, it's rare that I've found "I needed Something" without knowing what it was, and then stumbled on to a solution. I usually have a pretty good idea of a mechanic I need for a particular situation.
I mean, I understand how a writer can create a character, and "let them go" and "see what happens", but I just think that's different from a more structural component of the story.
Of course, as a corollary, there was an author talking about how in one story, he managed to back the characters into a corner. He then proceeded to write some other parts of the story, and when he got back to the earlier characters, they were out. They had escaped. Whatever corner they were backed into, they were no longer there.
And he did not write how that happened. They just "got out". He used the interim story to, essentially, distract the readers about what was happening before.
Cheap trick, but I guess whatever works.