They were probably there longer than you think. A large population of bugs doesn't come from nowhere all of a sudden in a clean environment. So they either showed up from somewhere, like hitched a ride, or something added to the soil; OR they were born there and their population grew till it exploded. I've had infestation problems a couple times but there are solutions. I know some might find it controversial but I spray down my grow spaces from time to time with an insecticide disinfectant in hopes to keep it clean and prevent bugs before they start. Haven't had problems in some time, knock on wood.
I also bake any new soil added to my grow in the oven to sterilize it. I rotate new soil and other amendments to my revolving soil and once I've got enough built up I rotate out to house plants. It's just an extra measure I take trying to keep bugs and their eggs from making their way to my grow.