I said earlier that I don't see the need for detective stories to have a theme, as brilliant plotting to me is an artistic achievement on itself. Some, however, do indeed have a theme which is essential to the plot even though it may not be obvious at first sight - Martin Edwards rightly pointed And Then They Were None as an example of this; one might also add John Dickson Carr's The Emperor's Snuff-Box which is basically about false appearances and not judging books on their covers. But the most perfect union of plot and theme in my view is to be found in Susan Glaspell's classic short-story A Jury of Her Peers.
I can see some of my readers cringe as this is not a detective story in the orthodox meaning of the term, and it's likely Glaspell didn't think of her work as such. Yet the two midwives indeed act as detectives, working the truth out of the clues, and the final (mis-)carriage of justice is one Sherlock Holmes wouldn't have frowned upon. So I think it qualifies, and so did the many editors who included the story in their anthologies.
A Jury of Her Peers is about the various degrees of female oppression, from mere condescension to downright abuse, but Gaspell - thanks heavens! - is no Sara Paretsky or Carolyn Heillbrun. She doesn't shove her message down the reader's throat or have her characters experiencing sudden and wordy "awakenings". She just let facts speak for themselves, and they do loud. Their shared experience of how it is to be a woman and a wife in that time and place allow Mrs. Hale and Mrs. Peters to understand what happened, who killed John Wright and most importantly, why - a truth that will forever escape their husbands and the D.A. for all their alleged superior minds. And their decision not to bring the murderer to justice is the logical outcome of that, even though it sounds more like temporary rebellion motivated by empathy than actual revolution. That is all: not a single useless word, no preach, no over-explanation and still the point is made. This is how all detective and mystery stories should be done - alas, all too often they're not.