Writing a murder mystery is different than other kinds of fiction. There are rules to follow, and there's the trick: to tell the story of a killing (or more) in an entertaining manner, when it's been done so often before, and so well.
Masters of the craft have offered their own insight. Listen to Agatha Christie give some tips during a BBC interview.
One of my personal favorites is James M. Cain, who advises (in the preface to Double Indemnity):
"I make no conscious effort to be tough, or hard-boiled, or grim, or any of the things I am usually called. I merely try to write as the character would write, and I never forget that the average man, from the fields, the streets, the bars, the offices and even the gutters of his country, has acquired a vividness of speech that goes beyond anything I could invent, and that if I stick to this heritage, this logos of the American countryside, I shall attain a maximum of effectiveness with very little effort."
Online, you can read the excellent Atlantic Monthly article written by Raymond Chandler, The Simple Art of Murder.
Elmore Leonard has 10 Writing Rules, the full context appearing on his website with an edited version below:
1. Never open a book with weather.
2. Avoid prologues.
3. Never use a verb other than “said” to carry dialogue.
4. Never use an adverb to modify the verb “said” . . .
5. Keep your exclamation points under control.
6. Never use the words “suddenly” or “all hell broke loose.”
7. Use regional dialect, patois, sparingly.
8. Avoid detailed descriptions of characters.
9. Don’t go into great detail describing places and things.
10. Try to leave out the part that readers tend to skip.
American Grand Master Hillary Waugh offers the following six rules:
1. All clues discovered by the detective must be made available to the reader. (This is where Fair Play comes in.)
2. The murderer must be introduced early. (This doesn’t mean he has to make a personal appearance, but the reader must know of his existence.)
3. The crime must be significant… usually murder, though kidnapping, blackmail, theft and the like will also do.
4. There must be detection. The solution must not be stumbled on; it must be sought and found.
5. The number of suspects must be known, and the murderer must be among them.
6. Nothing extraneous may be introduced.
Finally, from the creator of Phylo Vance, S.S. Van Dine, the following, oft-quoted twenty (20) stringent rules are proscribed:
1. The reader must have equal opportunity with the detective for solving the mystery. All clues must be plainly stated and described.
2. No willful tricks or deceptions may be placed on the reader other than those played legitimately by the criminal on the detective himself.
3. There must be no love interest. The business in hand is to bring a criminal to the bar of justice, not to bring a lovelorn couple to the hymeneal altar.
4. The detective himself, or one of the official investigators, should never turn out to be the culprit. This is bald trickery, on a par with offering someone a bright penny for a five-dollar gold piece. It's false pretenses.
5. The culprit must be determined by logical deductions - not by accident or coincidence or unmotivated confession. To solve a criminal problem in this latter fashion is like sending the reader on a deliberate wild-goose chase, and then telling him, after he has failed, that you had the object of his search up your sleeve all the time. Such an author is no better than a practical joker.
6. The detective novel must have a detective in it; and a detective is not a detective unless he detects. His function is to gather clues that will eventually lead to the person who did the dirty work in the first chapter; and if the detective does not reach his conclusion through an analysis of those clues, he has no more solved the problem than the schoolboy who gets his answer out of the back of the arithmetic.
7. There simply must be a corpse in a detective novel, and the deader the corpse the better. No lesser crime than murder will suffice. Three hundred pages is far too much pother for a crime other than murder. After all, the reader's trouble and expenditure of energy must be rewarded.
8. The problem of the crime must be solved by strictly naturalistic means. Such methods for learning the truth as slate-writing, ouija-boards, mind-reading, spiritualistic seances, crystal-gazing, and the like, are taboo. A reader has a chance when matching his wits with a rationalistic detective, but if he must compete with the world of spirits and go chasing about the fourth dimension of metaphysics, he is defeated ab initio.
9. There must be but one detective - that is, but one protagonist of deduction - one deus ex machina. To bring the minds of three or four, or sometimes a gang of detectives to bear on a problem, is not only to disperse the interest and break the direct thread of logic, but to take an unfair advantage of the reader. If there is more than one detective the reader doesn't know who his co-dedutcor is. It's like making the reader run a race with a relay team.
10. The culprit must turn out to be a person who has played a more or less prominent part in the story - that is, a person with whom the reader is familiar and in whom he takes an interest.
11. A servant must not be chosen by the author as the culprit. This is begging a noble question. It is too easy a solution. The culprit must be a decidedly worth-while person - one that wouldn't ordinarily come under suspicion.
12. There must be but one culprit, no matter how many murders are committed. The culprit may, of course, have a minor helper or co-plotter; but the entire onus must rest on one pair of shoulders; the entire indignation of the reader must be permitted to concentrate on a single black nature.
13. Secret societies, camorras, mafias, et al. have no place in a detective story. A fascinating and truly beautiful murder is irredeemably spoiled by any such wholesome culpability. To be sure, the murderer in a detective novel should be given a sporting chance; but it is going too far to grant him a secret society to fall back on. No high-class, self-respecting murderer would want such odds.
14. The method of murder, and the means of detecting it, must be rational and scientific. That is to say, pseudo-science and purely imaginative and speculative devices are not to be tolerated in the roman policier. Once an author soars into the realm of fantasy, in the Jules Verne manner, he is outside the bounds of detective fiction, cavorting in the uncharted reaches of adventure.
15. The truth of the problem must at all times be apparent - provided the reader is shrewd enough to see it. By this I mean that if the reader, after learning the explanation for the crime, should reread the book, he would see that the solution had, in a sense, been staring him in the face - that all the clues really pointed to the culprit - and that, if he had been as clever as the detective, he could have solved the mystery himself without going on to the final chapter. That the clever reader does often thus solve the problem goes without saying.
16. A detective novel should contain no long descriptive passages, no literary dallying with side-issues, no subtly worked-out character analyses, no "atmospheric" preoccupations. Such matters have no vital place in a record of crime and deduction. They hold up the action, and introduce issues irrelevant to the main purpose, which is to state a problem, analyze it, and bring it to a successful conclusion. To be sure, there must be a sufficient descriptiveness and character delineation to give the novel verisimilitude.
17. A professional criminal must never be shouldered with the guilt of a crime in a detective story. Crimes by house-breakers and bandits are the province of police departments - not of authors and brilliant amateur detectives. A really fascinating crime in one committed by a pillar of a church, or a spinster noted for her charities.
18. A crime in a detective story must never turn out to be an accident of a suicide. To end an odyssey of sleuthing with such and anti-climax is to hoodwink the trusting and kind-hearted reader.
19. The motives for all crimes in detective stories should be personal. International plottings and war politics belong in a different category of fiction - in secret-service tales, for instance. But a murder story must be kept gemuetlich, so to speak. It must reflect the reader's everyday experiences, and give him a certain outlet for his own repressed desires and emotions.
20. And (to give my Credo an even score of items) I herewith list a few of the devices which no self-respecting detective-story writer will now avail himself of. They have been employed often, and are familiar to all true lovers of literary crime. To use them is a confession of the author's ineptitude and lack of originality. (a) Determining the identity of the culprit by comparing the butt of a cigarette left at the scene of the crime with the brand smoked by the suspect. (b) The bogus spiritualistic seance to frighten the culprit into giving himself away. (c) Forged fingerprints. (d) The dummy-figure alibi. (e) The dog that does not bark and thereby reveals the fact that the intruder is familiar. (f) The final pinning of the crime on a twin, or a relative who looks exactly like the suspected, but innocent, person. (g) The hypodermic syringe and knockout drops. (h) The commission of the murder in a locked room after the police have actually broken in. (i) The word-association test for guilt. (j) the cipher, or code letter, which is eventually unraveled by the sleuth.
Source: Twenty Rules for Writing Detective Fiction
by S.S. Van Dine (pseudonym of Willard Huntington Wright) - originally published in the American Magazine (1928-Sep),and included in omnibus Philo Vance Murder Cases (1936).