I have become convinced that the fundamental appeal of the detective story lies in fantasies of autonomy.
Think about it. What does every detective story have in common? The hero or heroine who can move as freely as they choose from place to place, doing what they wish according to their own judgements as they make those judgements, managing their own time, roving from person to person conducting interviews, or from scene to scene gathering evidence or perceptions, entirely under their own steam.
Sherlock Holmes hangs around in his rooms until he decides to take a case, whereupon he follows the scent wherever it leads. He makes money from his cases and doesn't do any other kind of work. Poirot similarly - when he isn't on holiday, that is. Like Miss Marple, Poirot is retired and financially self-sufficient. Other classic detectives combine one or more of these traits. Spade and Marlowe run their own detective agencies. Some detectives are aristocratic and wealthy, some live off their earnings, but they are all, essentially, either unemployed or self-employed. Even the police detective characters - Morse, for instance - manages his own time. He leaves his batchelor home and goes to work, but once on the job he and Lewis perambulate around Oxford as they please, stopping off in pub after pub, etc etc etc. Most detectives, like Morse, are single. Some are apparently asexual, some widowed, some divorced, some eternal bachelors, whatever. But they tend to live alone or with a same-sex buddy like Watson. The queer dynamic is often there, but usually non-diegetic. There are detectives with families or busy personal lives - Wexford, Bergerac, etc - but even they leave their domestic or romantic entanglements behind while on a case, and rove around freely instead. Often, in these days when cop shows have to include loads of dour and gritty stuff about how being a police officer harrows your soul and consumes your relationships, the detectives with family lives are resolutely miserable, those family lives being a catastrophic mess of some kind. They then leave the mess behind when they zoom off to investigate. In this case the pleasure of ditching the domestic may be furtive and guilt ridden (the trope of the cop's wife glowering when he gets a phone call that will take him away from her) but it's still there. Called back to work, he doesn't have to go and sit in an office. Whatever the fictional copper's notional complaints about paper work, the body of the story will see him or her cruising from suspect to suspect in a car. The appeal is of not being tied in some way in which most of us are tied.
The original fictional detectives were a focus of anxiety about transgression of privacy boundaries. They tended to be eccentric masters of disguise, or common-as-muck policemen who broke into the middle class home to snoop (like Mr Whicher). The detective story settled into such a popular staple of modern fiction when the detective was transformed from a figure of disconcerting and nosy instinct (i.e. Dickens' Inspector Bucket or Collins' Sergeant Cuff) into the bourgois man of leisure (Holmes). He stops being an uneasy mixture of proletarian and spy, and becomes instead a middle-class investigator-as-hobbyist-or-small-businessman.
Here's the secret fantasy. It works in a way reminiscent of the American fantasy about solving guilt-problems held over from conquest which lies at the heart of the American ghost story. American ghost stories are all, fundamentally, about disputed real estate. British ghost stories are, of course, far more about the haunting of the modern by the feudal. Both are about capitalism vs some flavour of pre-capitalism. The detective story is, transatlantically, about some fantasy of freedom from the capitalist organisation of time or, relatedly, from the schedules imposed by the bourgeois family.