There seem to be two sorts of answer in this thread: psychological and literary.
Psychologically, I write for a-million-and-one reasons. I have a strong creative urge, and writing is something creative I'm particularly good at. I have a tendency to play out scenarios in my head--to plan, look ahead, and worry. That lends itself to playing out plot scenarios. I also tend to play out conversations in my head, both before and after they might happen or have happened. So, I'm replaying a conversation and thinking, Why didn't I say this or that? Or I'm thinking about some conversation and planning out what I'll say--which is pretty much never what I actually end up saying, of course. But in my head, I always have smart and witty things to say. When it comes to actual conversations, not so much. I forget to say/ask important things, I forget what people tell me... Writing is basically a way for me to get my say. I can get down all my clever little thoughts with time to fix it up and make it all as good as it can be.
On the more literary side, as far as what sparks actual ideas: a lot of things, but mostly other stories. This is usually stories from history, since I write historical fiction. For instance, I wrote a novel based (very, very loosely) on the life of Fanny Kemble, an English actress who married a Southern plantation owner, without apparently knowing he was a plantation owner, and ended up divorcing him. And I wrote a novel based around the story of a Southern civilian woman who went out and cared for the wounded of both sides during a battle near her home. I wrote a novel about the real brothers who inspired Peter Pan; the structure was inspired by Lincoln in the Bardo. It's usually a "what if" or a "bringing it to life" kind of impulse.
Of course, recently I've been in a weird place mentally and emotionally and haven't had the urge to write at all in the last year or so.