They didn't.
It's a development that happened gradually over several thousand years.
And while agriculture developed independently in several parts of the world, this wasn't at the same time at all.
You can call it "sudden" in a geological timescale, but not when measured against human lifespan.
Your question makes zero sense.
Farming is not a genetic trait.
This is a great example of GIGO: garbage in, garbage out.
When you start with nonsense assumptions, only more nonsense follows
Farming comes from the brain, with the human brain more than the sum of its genetic parts. Our natural collective human propensities and instinct evolved with the DNA and natural selection, and are engrained in the brain. However, the brain, via the ego, can externally learn beyond what is written on the DNA; cultural knowledge. The iPhone is not part of the human DNA, but the invention appeared due to the brain being more than the sum of the generic parts. We are not stuck at instinct and that is it. The human brain is where the DNA centric approach to evolution, falls short. This is evident with the rise of civilization, where there is full departure from the old ways of genetic based instinct. Cain symbolically kills Abel and farming supersedes migratory herding and gathering. The symbolism shows the change being quick.
For example, early humans migrated all over the earth. This would be more of a function of the brain reacting to altered environmental parameters that may have triggered survival instinct. In this case, it is a team effort of DNA and the real time situational brain. Natural selection can be a combination; genetics plus what is more than genetics via the brain. The current DNA model of evolution is half baked and needs an update.
The earth had a mini-Ice age as recent as 10,000 years ago. The urge to move south; in the Northern Hemisphere, may have been connected to having enough sense to follow the animals, who lived there, and who may have made his journey before; change of seasons. Farming could be due to being tired and deciding to stop and not have travel all the time, as the climate began to stabilize more south.
The hunter gatherers ate seeds, among other things, and noticed spring seeds sprout and spouts taste good; gourmet, and also form new plants. The brain in an inspiration, does an experiment, and sure enough you can grow your own seeds; early applied science. Once theconcept is proven others copy and make further process improvements.
The rise of the human ego or secondary center was key, since it was semi-separated from the instinctive DNA based primary; inner self, and could make separated decision making. This is why change quickens about 6000 years ago. While the impact of the ego has an impact on the DNA based inner self, which can help do main frame data crunching for advanced building projects; pyramids.
Many scientists do not believe that ancient civilization could do some of the things they did, and some postulate aliens. However, the DNA based inner self has much more capacity and could help the ego get over the top.