There can be several ways that the Borg were created. My theory is that Starfleet, in the TOS period, began dabbling in nanomachines. A flaw in the nanomachine's programming turned the test subjects into unstoppable cyborgs intent on spreading their infection to others. The Borg, having not discovered how to adapt to phaser weapons, retreated into the Delta Quadrant using a detached saucer section from an Excelsior-class prototype equipped with transwarp drive (in the early models of the Excelsior, the warp drive system was built into the saucer section) when the remaining crew were able to effect a succesful resistance. Starfleet, unable to piece together what had gone wrong, forbade the further production of any nanomachine technologies.
What are your theories?