I'm not exactly sure how it came about, but I do know that some history books will say that the hypothesis existed in 350 B.C.E. Scientists preformed expermiments that apparently supported this hypothesis, and so it quickly became a theory.
In the 17th century, men like Jean Baptist van Helmont preformed experiments such as leaving sweaty tee shirts in closed boxes, and he would com back to find mice in the box. Also, a long, long time before this, Aristotle actually had others feel slimy substances at the bottom of rivers, and used it as a way to explain where certain fish came from. Of course, the idea was that these organisms were the result of spontaneous generation.
A number of other experiments were preformed in support of this "theory," but certain individuals started to do experiments that revealed the flaws in the theory of spontaneous generation. For example, Francesco Redi did the famous "meat-in-the-jar" experiment as some call it. He took several hunks of different kinds of raw meat and left them in jars, he sealed them, and nothing appeared. Proponents of the theory of spontaneous generation said it was merely because there was no air, and therefore it was impossible for organisms to spontaneously generate in an environment with no air.
He preformed the experiment again with a net-like covering over the jars, and since the netting was good enough to keep the even extremely tiny insects out, maggots didn't form on the meats. Of course, this was a huge breakthrough (and tragedy to some) for the science of life. After a while, though, some started to say that although organisms like maggots and fish (etc) might not come from meat or the slime on rocks at the bottom of rivers, that didn't mean that organisms didn't spontaneously generate.
After a while, microorganisms were discovered. They would leave something untouched, and microorganisms would appear on it, and they believed this was spontaneous generation in action. In the 18th century, John Needham showed that a broth (which they called an infusion) showed evidence for spontaneous generation. You see, he took the infusion, and he boiled it, apparently killing all of the microorganisms. However, even though the infusion was sealed after "all of them" were dead, he saw that microorganisms appeared regardless.
However, a Frenchman Lous Pasteur thought otherwise. He had a flask with a curved neck, which was pretty genius. You see, the curved neck allowed for microorganisms to make it through a part of the neck and then become trapped a ways through. See, through the neck was another infusion. After he showed that no microorganisms appeared, he tipped the flask, allowing the microorganisms to make it through. This showed that they did NOT spontaneously generate. This experiment was of course repeated.