The answer is simple. The agents working on the Weiner case, who were not even FBI, discovered the emails. It took them a long time to work their way up the chain of bureaucracy to Comey.
More likely Comey was sitting on them hoping to hide them until after the election but his hand got forced either by the NYPD saying they were going to put them out or by his own agents giving him an ultimatum. Either way they were going out, the question was whether Comey was going to go down as leading a cover up or go down for putting them out so late.