I don't write many mysteries. When I have done, what I usually do is to create the crime first. And I obsessively craft it--I use drawings, scale models, full-scale semi-reenactments (wherein I play all roles, and no one watches, but it gives me tips on the physics of how things work).
From that, I usually have a large collection of clues. I also have my criminal (murderer, say), and my victim, along with the motivations, and other characters and suspects surrounding the case, because they all play a vital role in the murder, no matter how subtle it may be. I know every detail before I even begin.
Then I put my detective into the story and begin writing.
This is completely the opposite of what I usually do--write blindly from a starting point of a couple of characters and a vague notion of what the situation might be--but it's important for me, when writing a mystery, to make sure everything fits together perfectly the whole time, because I view a mystery as an intellectual puzzle. If any pieces of the jigsaw are missing or don't fit, the end product won't make any sense.