The air inside a plane gets continually recirculated and some people have such a severe allergy that even the smallest traces can causes a bad reaction.
Face masks are effectively preventing droplet infections, but probably wouldn't prevent traces of peanut from being inhaled.