They probably came from the soil. I did have fungus gnats early this season, and they were in the soil. I found the larva in it. After that, I have been sterilizing all of the bagged soil that I have used this season. I am also using water with Mosquito Dunks in it every time I water. I got rid of them, and they haven't come back.
The life cycle is quite long. At 22 C (about 72 F), the egg takes 3-6 days to mature, then they spend about 2 weeks moving through the larval stage, and then another 3-6 days as a pupa, so it could take almost a month from egg to hatching. It would take longer if the temperature was cooler, and shorter at warmer temperatures, I would think.