I forget the exact phrasing of the question, but a while ago a friend asked, hypothetically, whether copying genes from peanuts into another plant would result in potential anaphylaxis due to peanut allergies in anyone consuming that plant. I can’t remember if the situation was entirely hypothetical or based on a real-world application, and when I google I’m only finding a lot of buzz about non-allergy-causing genetically modified peanuts. But let’s use the situation anyway — after all, there are bound to be organisms that cause allergies or contain toxins with useful genes that might be transplanted into other organisms destined for human consumption.
Really, I think there’s only a risk if the same protein that causes the allergy or the toxic effects is the one which also produces the desired effect, say… drought resistance — or perhaps more likely to be playing both roles, insecticidal properties. In that case, when we copy the desired gene from the peanut (or pufferfish, or poison ivy, or so on and so forth) into the consumed organism, we would indeed cause the food/medicine-producing organism to produce a protein that can cause a deadly reaction in humans.
However, most of the time, it’d be unlikely that the protein useful to us (which makes a plant toxic to insects or resistant to drought, etc) also causes the allergy. So in copying just the DNA sequence responsible for the useful effect of the source organism, we don’t copy over the DNA of the allergen or toxin. Thus the target organism doesn’t make the allergen or toxin, and there’s no allergy or toxin.
There are definitely cases where we don’t know whether a particular protein would cause a reaction in humans, because we’d never typically consume the organism it originally comes from. That kind of thing will require testing, as a matter of course, starting in cell cultures and working all the way up to living healthy humans, before it ever sees at-risk groups. Despite all the horror stories about GMOs, there are established ways of testing new compounds in humans and they will be followed in those cases too.