KABUL — The spectacular collapse of Afghanistan’s military that allowed Taliban fighters to walk into the Afghan capital Sunday despite 20 years of training and billions of dollars in American aid began with a series of deals brokered in rural villages between the militant group and some of the Afghan government’s lowest-ranking officials.