There are lots of beans that grow wild in Africa and Asia, so people were already used to eating beans before they came to the Americas. When people first came to South America about 20,000 years ago, they probably began right away to pick and eat wild pinto beans. Beans have a lot of protein, carbohydrates, folate, and iron. You have to boil beans before you can eat them, and so people boiled them until the beans turned into mush. Then they ate the bean mush as soup or porridge.
By about 5000 BC, people in South America were farming their own beans. At least two different groups of people began to farm beans independently of each other. In South America, farmers began to grow a type of bean that grew on bushes, and was easy to pick.
In Central America, where people were already growing corn, they began to farm a kind of bean that grew on vines, so you could plant it next to the corn and it would support itself on the corn stalks. They ate the boiled bean mush spread on corn tortillas or tacos, as we do today. They didn't fry the beans to make refried beans, because they didn't have any fat to fry in. With the beans, they had avocados and tomatoes and onions and chili peppers.