Villages appear long before defensive fortifications in the record, in many cases. Pure reason is not very good at forming predictive theories about history, as a general rule.
There are many possible reasons for villages, and cultural reasons are a very big determinant of how people live. So are economic reasons. Many of us live in big cities now, and it's generally less safe.
Foraging sucks less than subsistence farming. However farmers are able to put a lot more people into given land area and so farming villages won out.
A village has a lot of land to defend and not many people to do it. The local town or city sized group will just pitch up with many more men and overrun you. All whilst having enough people left for defence. And they are likely to have more access to heavy weapons that can blow your house up from a distance.