Some time before the end of this review, I will have stated whodunit. This should not deter you from reading Kate Summerscale's book, because, as with all the best detective stories, the "who" is by no means the most interesting or salient revelation. Readers may flock to crime stories for the element of game-playing or puzzle, but such novels (and a lot of true crime, too) tell us more. They delineate a culture, comment on class and society, and ask their readers big questions about morality and human nature.

The murder of a small boy at Road Hill House shocked Britain and was a cause célèbre even further afield. Dickens was intrigued by it, Wilkie Collins and others borrowed from it, and the public (through newspapers and broadsides) couldn't get enough of it. The detective at its centre was pilloried in Punch and retired a broken man, but even after the culprit was brought to justice (or, rather, walked towards it willingly) there were twists outstanding.

On the morning of Saturday June 30 1860, Saville Kent, aged three years and 10 months, was found to be missing from his bed at Road Hill House, on the edge of the village of Road (these days renamed Rode), on the border between Wiltshire and Somerset. Before long his body was discovered by servants, stuffed down a makeshift toilet in the grounds of the house. His throat had been cut. The boy's father, Samuel Kent, was not well liked. His task was enforcing the 1833 Factory Act, which made him unpopular with employers and employees both. He also erected high fences around his home and added No Trespassing signs.

What soon became clear, however, was that the killer knew the layout and sleeping arrangements in the house. Little point erecting fences and warning notices when a murderer lurked within rather than without. Summerscale is very good on the mores of the time. An Englishman's home was, indeed, very much his castle. The middle classes were in the ascendant. The railway had arrived at nearby Trowbridge just 12 years earlier, bringing jobs with it. Murders were supposed to happen on the desperate streets of London, not in the bedrooms of well-tended rural children. The local police were reluctant to disturb the Kents. Summerscale tells us that there was "some hesitation in intruding on the family privacy". They were also resistant to interference from London.

Jack Whicher was one of the eight original Scotland Yard detectives. Summerscale describes them as "all-seeing little gods". This was certainly the public's perception, though the apparent failure of the Road Hill House inquiry would lead to scepticism and a souring of relationships. Whicher was 45 and had a string of successes behind him. The Metropolitan police detective branch had been in existence for 18 years, and Whicher, as a detective (rather than one of the uniformed "peelers"), worked undercover. Two years before Road Hill House, he had apprehended a thief who had made off with a Leonardo da Vinci. He had also aided the hunt for some revolutionaries who had attempted the assassination of Napoleon III in Paris. Dickens (whose character of Bucket in Bleak House was broadly based on Whicher's friend and boss Charley Field) knew Whicher and had eulogised the new breed of detective as "models of modernity" in several magazine articles and stories. Until now, the trend in fiction had been for crime stories about dashing crooks. Dickens and Collins would shift the focus to analytical detectives who were, like Dickens himself, largely working-class boys made good.

Some, however, were resistant to the very notion of detectives. "There will always," barked a Times leader, "be something repugnant in the bare idea of espionage." Whicher was certainly not wanted by the local police in Wiltshire and Somerset. Their view was that the killers had probably been Saville's own father and nursemaid. (Kent had "previous", having married the children's governess after his first wife went mad and died.) Whicher, however, soon formed a different conclusion, one based on psychology and instinct. For him, the prime suspect was Saville's half-sister Constance, aged 16 at the time. Whicher was swayed neither by village gossip nor by intrusions by phrenologists and hoaxers. One particular story in Constance's past suggested to him that she might be leading a double life. Four years previously, she had run away from home accompanied by her brother William. Before leaving, she had gone into the same outdoor privy to change into a boy's clothes, cropping her hair at the same time. "The real business of detection," Summerscale informs us, "was the invention of a plot." Whicher believed he had both a plot and a motive - jealousy of her younger sibling. Sigmund Freud would later compare detection to psychoanalysis, and the author suggests that Whicher was investigating Constance's "hidden psychic material ... The murder was so dense in symbolism that it almost outdid interpretation."

Most onlookers were appalled at the notion that a child could have carried out such a crime. But then it also appalled them that a middle-class father could have been guilty. While The Woman in White was undergoing its gripping serialisation, Constance was examined by local magistrates. Her defence lawyer made a mockery of Whicher's inquiries and guesses, while the local constabulary campaigned to discredit the Londoner.

Anonymous pamphlets were issued, books were written, theories flooded in, and at least one journalist bluffed his way into the Kent household to ask some questions of the master. In fact, what is so extraordinary about this whole story is how modern it feels. When one newspaper pointed a finger at Samuel Kent, a libel writ was soon issued, while Constance received proposals of marriage from her "fans". Easy enough to imagine both still happening today. The detective, meanwhile, was being denounced in parliament for his ineptitude. The home secretary ordered a fresh inquiry and the nursemaid, Elizabeth Gough, was arrested (but eventually released). As theories came and went the press, and Dickens, became disillusioned with detectives. What was needed, it was decided, was a kind of detective who was "not so much a scientist as a machine".

As the case became fodder for fiction, so Whicher shuffled away from policing. But in 1865, a year after his retirement, Constance walked into Bow Street magistrates court to confess to the crime. The problem for the reader at this point is that we cannot know how Whicher himself feels - because the bald facts of the case give no indication. Whicher, our guide through so much of the book, has "left the stage". Likewise, we are not told how devastated the members of the family may have been by the murder. We cannot know the inner workings of anyone's mind. In particular, I missed any concentration on the second Mrs Kent, the former governess. Saville was her child, while Constance was not. This is where novels come into their own: they allow us to move beyond surface appearances towards a deeper understanding of motivation and psychology. There is some terrific detail in Summerscale's book (Whicher's face, scarred by smallpox; the woman selling pigs' trotters outside Great Scotland Yard) but overall the feel is of dry, courtroom testimony. The author rightly suggests that the Victorian detective was "a secular substitute for a prophet or a priest ... he offered stories that could organise chaos". The organising of chaos is also what novels do well. Indeed, they do it so much better than real life, which is why we read them. Summerscale is persuasive in tying the Road Hill House case to movements in crime fiction at the time, but the murder itself lacks the intricacies and niceties of the novel. What the book does brilliantly, however, is look at notions of class, criminality, human nature and religion in an age of change.

Constance, by this time the subject of a Tussaud's waxwork, was saved from execution by Queen Victoria, but served 20 years for the crime, then disappeared. Newspapers still felt that the details of her confession didn't add up. Having been vindicated, Whicher went back to work as a private investigator and played a role in the case of the Tichborne Claimant. The Moonstone borrowed from the real-life Road Hill House case and it was also revisited by Dickens. (Dickens, incidentally, had misguessed the identity of Saville's killer.) The "sensation" stories of the earlier part of the 1860s, which the philosopher Henry Mansel feared were "a virus that might create the corruption they describe", becoming in the process "agents of social collapse", had been replaced or "tamed" by the detective novel.

Whicher died in 1881, while his protégé Frederick Williamson went on to help found the CID and lead the hunt for Jack the Ripper. As for Constance herself ... well, you'll need to read Summerscale's engrossing book to find out. You didn't think I'd give away the real ending, did you?

· Ian Rankin's final Rebus novel, Exit Music, is published by Orion

Sign up for the Guardian Today

Our editors' picks for the day's top news and commentary delivered to your inbox each morning.