One of the questions writers of fiction hear most often (if not the most frequent) is "Where do you get your ideas?" I usually give a semi-facetious answer: They're all floating around in the ether and when you're tuned in they just come to you.
Facetious, but as good an explanation as any. I can pinpoint where certain books started. Sometimes I began with a great title: Styx and Stones, for instance.
Once I had that, it clearly had to be a poisoned-pen story, so the characters, plot, and setting developed from there. But what sparked the title I have no idea.
It's easier to trace the books that started with a place: Rattle His Bones, set in the Natural History Museum;
The Bloody Tower, set at the Tower of London;
or To Davy Jones Below, set on a transatlantic liner, and Murder on the Flying Scotsman, on a train. In each case, the place--the setting--led to the plot and the characters. Where the Flying Scotsman is concerned, another factor was that I wanted to make it as different from Murder on the Orient Express as possible, though that's where the idea came from.
(The cover on the left, the US hardcover original, was developed from a real 1920s railway poster--which did not, however, have a skeleton driving the train)
So, sometimes the origin of an idea is clear. More often, I haven't a clue, or not one I can pin down. I guess the real answer is: A lifetime's experiences.