It's a pleasant surprise. That is one of my favorite parts about writing, the discovery. I didn't have a plan for what happened so I will be spending my time filling in the blanks and digging into the characters motivations. On many occasions I don't know why they did what they did so I have to spend a lot of time trying to figure that out so I can make sure there is consistency with them as well as the plot. Characters are people too. I know I am not the only writer who has imaginary people in their heads doing the unexpected.
"I invent nothing, I rediscover." --Aguste Rodin. I think that is all I ever do. I feel like I, and any creative person, have access to secret worlds that no one else does. The act of creating is to give other access to these secret places hidden inside all of us.