The transition from practical science into mystery writing was a natural one. Essentially, science seeks to solve the mysteries of the universe. Below on the left, this diagram shows the Scientific Method, which is the accepted stepwise process for conducting scientific endeavors. After making observations, a scientist poses a question, which is answered by a hypothesis. A hypothesis is a statement about the question that can be disproven or rejected. The scientist then conducts experiments to test their hypothesis. Once the experiments are complete, the scientist can reject or fail to reject their hypothesis, which leads to a conclusion to their question. It may not be the answer, but it will provide information hopefully leading to the answer eventually. It is a cyclical process that repeats ad infinitum.
Below on the right is a similar diagram showing the structure of a mystery story. Of course, stories can vary in their presentation, but generally every mystery story has a central crime. After the crime has occurred, a detective or other character collects clues to inform a theory of what has happened. When the detective is confident in their theory, there is a confrontation with the criminal. And like science, when the theory is tested, there is a conclusion to wrap up loose ends in the story and perhaps point to future stories.