Androids, most of them Replicants that were still alive after the events of NieR concluded, didn't fight the aliens from the get-go. The aliens landed during year 5012, about 800 years after humanities extinction. I would imagine that newly created androids and replicants lived their lives happily up until this point trying to find a way to revive humanity. It was Emil who created copies of himself to fight off the aliens for the first engagements against the Aliens. He created over 85million copies, loosing most of his memories in the process. The aliens quickly considered him to be some kind of greater god and instead of fighting him directly created the machine lifeforms in his likeness to finish the battle for them.
There was a point in time where P-33, or Beepy as he was nicknamed by his shade-friend, the Robot from the first NieR, managed to ascend from the junkyard to see machines, androids and aliens living together peacefully (
The Fire of Prometheus shortstory, year 5645). At some point fighting must have restarted though and the androids started creating squads to fight the aliens in a more organized manner. This has gone on for more than 6000 years, and the fact that most androids are kind of bland and do not resemble the replicants we know from the first game at all, leads to believe that over time most replicants died during battle or "naturally" and had to be replaced with inferior androids that were no longer created from Gestalt-data. Those models were required to have a goal to live for, since they didn't possess the natural human will to live that was still active in replicants.
Why the fighting restarted isn't really explained, though I do think that the red girls from the games ending had something to do with it. There's a reason a lot of the machines aren't initially hostily, since only the ones still connected to the network receive transmission from the "hivemind". Being severed from the network seems to happen quite often, which is why some of them decided to form their own "society" based on human data - the forest kingdom being a good example here. Co-existence apparently was possible but didn't further the ultimate goal of the hivemind: Evolution.
It isn't far fetched to believe that these conceptual human beings were the ones to give the commands to the machine life-forms, and not the aliens themselves, to gather data and evolve further. Once sufficient data had been gathered from the alien/machine/android conflict, they would've destroyed the moon server to remove the foundation of the conflict and not bother with Earth anymore, only to continue their evolution elsewhere. The function of the tower gets changed during Ending D, where it shoots an ark instead that lets the machines aswell as 9S (if you choose so) leave for another world.
Another reason for the resurgence of the fighting might be the influence of the cult of the watchers. Eve is clearly shown to have the symbol of the watches on his chest and since the machines managed to obtain data from all of human history, they may have eventually come to find out about the cult of the watchers. The watchers ultimate goal was the destruction of humanity, same as the machines/aliens that are still connected to the network. Since the conceptual human beings not only have a striking resemblance to Manah, but also talk in both a young female aswell as an older male voice, same as Manah again, it makes me want to believe that this is the main reason for the conflict.
YorHa itself was set in motion before the start of the 14th machine war. The
stageplay Yoko Taro wrote, which is somewhat rewritten in the game as the the novella 'Pearl Harbor Descent' (year 11941), is referenced as the first successful operation of the prototypes that eventually became the current project YoRHa combat models. You can read about it during A2s 3rd chapter in the 3rd playthrough, visit the resistance camp and talk to Anemone. This mission spurned the creation of the Type-E model, since A2s black box signal was still active and the mission itself was supposed to be a suicide mission. I am fairly certain that the server they were destroying did actually contain data about the lunar-server, the machines clearly hacked as deep into the moons server as they could so its destruction was important for multiple reasons. YoRHa did obviously not know about the Tower structure that had a library of all data as a back-up for the machine network. Project YoRHas combat model production may very well have been a reaction to the machines trying to hack into the moon-server.
There's no reason to believe the creators of YoRHa having to be more advanced/intelligent than YoRHa itself, they just figured that instead of recreating androids from the remaining human-data they had to create actual combat models that each had their own specific sub-set of skills, both to keep information compartmentalized aswell as being able to create squads that specifically fit their needs in pursuits of their ultimate goal - destruction of all data referencing humanities extinction. This is why they're the only ones to try to keep emotions to themselves during missions, though it is rarely punished if they do. Only 2E has a proper reason to not become emotionally evolved, most other YoRHa don't seem to care much about this "rule".
The YoRHa command had to be set in motion a lot earlier, since this appearance of YoRHa models is called the first "successful" operation of project YoRHas combat models. Seeing how setting up orbital stations, servers that communicate as if humanity was still alive and creation of prototypes for a project of this scope surely takes some time, it is quite hard to say when the project was actually set in motion. Could be 50 years ago, could be 5000. It is just that combat-model production has pretty much just started a couple of years before the game steps in, the non-combat side of things may very well have existed for hundreds or thousands of years.
The project itself was ultimately designed to be shut down by the pods (which is what happens during ending E up until Pod 042 intervenes) after the YoRHa combat models got rid of all the evidence that humanity was in fact extinct.
In the end alot of the original androids were still somewhat related to the old replicants, which had actual individual human data that created them. Most of them were not suited for combat at all but still had the humans will to live inside them. The newly created combat-models were inferior in that regard which is why most of them simply want to die when faced with hardship/angst and the machines were close to finding out the truth themselves, so something drastic had to happen to keep them working properly. Queue, Nier:Automata.
I'm not sure if there is any date associated in one of the hacking sections that can be used to gauge when the project was actually initiated.
My biggest question still remains: Who the fuck created Accord. She seems to be an advanced version of the pods and the shopkeeper in the resistance camp actually mentions her by name again (similar to most shopkeepers in the franchise).