Winnie Holzman (who wrote the Wicked screenplay and the book for the stage musical):

There were so many conscious and unconscious ingredients. The writing process has a mysterious quality and who really knows how that happens?

Source: Interview