Multiple reasons. There is still a lot of research on this topic. And multiple environmental and genetic factors. Some studies suggest that touching certain foods prior to eating them increases our sensitization. There are studies looking into whether children with eczema and atopic dermatiits are more prone to food allergy secondary to the poor skin barrier.
Genes + Exposures. There are genetic predispositions for allergies in general, and to specific types of allergies as well (e.g. Food vs medication vs environmental allergies). However, just the genetics does not guarantee developing an allergy. There must also be an exposure in the "right" situation to trigger the allergy. The details of the "right" situation remains unclear.
Great question! We know that genetics play a part. Allergic parents tend to have allergic kids. Exposure to the food allergen is controversial. It appears that early exposure to foods can cause allergies to develop. How early is the question. Some recent studies even show the opposite effect. I always counsel high risk kids, to avoid highly allergenic foods early. Foods such as nuts, peanuts, shellfish.