The seventh commandment of detective fiction is:
The detective must not himself commit the crime.
In his 1939 commentary on his decalogue, Fr. Knox said:
This applies only where the author personally vouches for the statement that the detective is a detective; a criminal may legitimately dress up as a detective, as in The Secret of Chimneys, and delude the other actors in the story with forged references.
In many ways this is a counterpart to the first commandment, specifically the part about “but must not be anyone whose thoughts the reader has been allowed to know”, so some of that analysis will apply here.
Incidentally, I can’t help but wonder what Fr. Knox would have thought of the final Poirot novel, Curtain. (Technically, it should be noted, the detective in the novel is Captain Hastings, not Poirot, and there is more than one murderer in the story.) It seems like Agatha Christie made a habit of violating Fr. Knox’s ten commandments and doing it in a way that worked.
Be that as it may, I agree whole-heartedly with this commandment. Having the detective commit the crime destroys the basic structure of a detective story and turns it into a weird mockery of itself; a detective who merely investigates himself becomes nothing but an empty puzzle with no meaning or value.
Having said that, this commandment is one of the least transgressed commandments in detective fiction. There’s a highly practical element to this: most people write series of detective stories featuring the same detective. Having the detective be the murderer once will ruin the enjoyment for the readers of any subsequent stories; having him be the murderer more than once will ruin even the surprise. Who would read a story in which the central mystery was the foregone conclusion of a twist which can be relied upon? So the mere fact that mysteries are written as series tends to safeguard writers from this bad decision. It is true that sometimes self-interest will do the work of virtue.