Wouldn't it be nice if there was a straight answer to this question? Wouldn't it be nice to be able to say something about how inspiring the world is and how the poetry of the galaxies gives you ideas? Wouldn't it be nice if there even was an answer at all?
I speak for many (if not most) writers when I answer this question: I don't know.
Really, I don't. I can count on one hand the number of story ideas I can trace back to a specific source of inspiration. For me, story ideas just happen. I can't explain it. One minute I'm innocently standing in the shower, taking a physics exam, or walking a dog at work. The next, I'm bombarded with this idea. This idea may start as a little nagging at the back of my mind, but within a matter of minutes, it's capable of blocking out every other thought until it's all I can focus on. And it comes out of seemingly nothing. Ideas ex nihilo.
It can get pretty distracting. How am I supposed to focus on mundane things when my brain is going "DYSTOPIA. HISTORICAL FANTASY. INTER-DIMENSIONAL TRAVEL VIA NARWHAL. MAKE IT HAPPEN." (What's that? Your brain doesn't think in caps lock? I can't comprehend having a brain like yours.) The writer's brain is fully capable of a disturbing single-mindedness when it comes to that flash of a new idea.
Writer: Brain, what are you talking about? Historical dystopia isn't a thing.
Brain: MAKE IT A THING.
Writer: And...narwhals. Narwhals? Really? Narwhals are terrifying.* Can't I just sleep?
Brain: THERE ARE MORE IMPORTANT THINGS IN LIFE. LIKE THIS IDEA.
Writer: What if I say no?
Brain: YOU ACT LIKE YOU HAVE A CHOICE.
Now that your brain has decided to focus on a historical dystopia featuring inter-dimensional travel via narwhal, that's it. You have no idea where that came from, but now you have to deal with it. Trying to shove it away only makes it worse. It's like saying "Don't think of elephants!", because as soon as I say it, you're thinking of elephants.
There's no logic to it. There's no rhyme or reason. It's madness without the method. It would make more sense if the ideas actually came from a logical place, but nope, they don't.
Writer: *passes by an old, decrepit barn*
Brain: Wow, maybe it's haunted. That would make a cool setting for a horror novel.
Writer: Hey, awesome idea!
Writer: *passes by an old, decrepit barn*
Brain: YOU KNOW WHAT YOU SHOULD WRITE ABOUT? SENTIENT PIRATE SHIPS.
Some people like to call these random ideas "plot bunnies". It makes sense, in a way, because novel ideas multiply like, well, rabbits. Still, I've never liked the term "plot bunny". "Bunny" implies that it's cute, fluffy, friendly, and easy to manage. I can't remember the last time I had a plot idea that was cute, fluffy, friendly, and least of all, easy to manage.
You may think I'm weird because my brain regularly bombards me with random ideas. The truth is, I've never known anything else. I don't know what it feels like to have a brain that doesn't start plotting novels in the middle of a physics exam. And yet, I wouldn't want it any other way. I don't want to live without a brain that decides it's plotting time when I'm trying to sleep. How people live without it is beyond my comprehension.
For me, it never quite feels like the stories are actually coming to me from somewhere. It feels like they've been there all along, and something has now triggered them and brought them into the forefront of my mind. I'm starting to believe that a writer is born with every story idea they'll ever have already embedded inside them. Maybe some of those stories will never even come out, and most will be useless, but they're still there. They've existed all along.
(I tried to come up with a good analogy for this, but the only one I could think of was weird and borderline uncomfortable, so I just didn't.)
I love this way of thinking. It's not that a writer is born an empty vessel, waiting to be filled with experiences that can be transferred into stories, poetry, or other words. Instead, I like to think that a writer is born with the seeds of all the ideas they'll ever need, and experience teases these ideas out into the open. Maybe this explains the apparent randomness of most ideas. Science, I'm waiting for you to prove this somehow.
Non-writers: the next time you ask a writer this question, you'll know why they're looking at you like the GIF below. They may not understand it, but you'll know why. It's okay; your writer friend isn't asking you to understand, just to be okay with the "How should I know? My book ideas come from places that make no sense."
Writers: Can you relate?
*Expectation: this. Reality: this.