When we are talking about the grains and vegetables, the pesticides they contain, comes from the pesticide used during their cultivation in the field. If these are not washed properly, some traces of pesticide remains there.
Pesticides are chemical compound and are very stable. When any animal eats these plants, the pesticides enter into the body of that animal. The concentration of these chemicals increases at each tropic level. This increased accumulation of harmful chemical in the body of living organisms at each tropic level is called biomagnification. This is the reason, why meat of animals which eat pesticide contaminated plants also contains pesticides.