Epigenetics
Epigenetic structures are structures that cover genetic structures, i.e. DNA, and govern how the genes of the DNA express themselves. DNA only changes over the course of millions of years through evolution, or suddenly through mutation. However, organisms need to be able to adapt to daily changes in their environment, and epigenetic structures turn genes on and off on a day to day basis to allow organisms the ability to cope with daily challenges and needs.
Experiences Passed On To Children
Not only are genetic traits of DNA passed on to subsequent generations, but so too are epigenetic traits. The Överkalix study showed that children whose grandparents had lived through either a feast or a famine season before giving birth passed on the symptoms of starvation or gluttony to subsequent generations via epigenetic structures:
Among the 1905 birth cohort, those who were grandsons of Överkalix boys who had experienced a “feast” season when they were just pre-puberty—a time when sperm cells are maturing—died on average six years earlier than the grandsons of Överkalix boys who had been exposed to a famine season during the same pre-puberty window, and often of diabetes. When a statistical model controlled for socioeconomic factors, the difference in lifespan became 32 years, all dependent simply on whether a boy’s grandfather had experienced one single season of starvation or gluttony just before puberty. It appeared that Överkalix grandfathers were somehow passing down brief but important childhood experiences to their grandsons.
(Source)
Magic Passed On Via Epigenetics
So, even though some of your characters may not have genetic predispositions for magic, if their parents gain powers via environmental exposure, such experiences can easily be explained as being passed on to subsequent generations via epigenetics.
Magical Ability Via Genetic Mutation
Sudden changes in genetic traits can be effected by mutation, allowing brand new traits to be gained in one generation and subsequently passed on to offspring. Perhaps your environmental exposure to magic causes benign, useful genetic mutations giving parents fully functional, beneficial genetic traits for magical ability.
Normally mutations are not always beneficial, since mutations are generally random in nature, but perhaps exposure to magic by it's very nature causes specific, beneficial mutations to DNA that grant magical abilities. These abilities would then be passed on to subsequent generations in the newly mutated DNA.
Differences of Genetic vs Epigenetic vs Mutated Traits
Essentially there is no difference, so far as I'm aware, between how normal genetic traits and mutation-caused genetic traits manifest themselves in offspring--so far as I'm aware, they both are treated as genetic traits, i.e. traits manifesting in the DNA itself.
However, traits manifesting due to epigenetics are significantly different, as I understand them--epigenetic mechanisms allow existing genetic traits in the DNA to be activated or deactivated on an as-needed basis:
Epigenetic factors are compounds that attach to, or "mark" DNA. These factors interact with genetic material, but do not change the underlying DNA sequence. Instead, they act as chemical tags, indicating what, where, and when genes should be "turned on" or expressed.
(Source)
So, this makes me wonder if epigenetics can carry and manifest a brand new trait not found in the DNA, or whether epigenetics can only effect traits already existing in the DNA. I've researched this a bit and cannot find an answer. Epigenetics is a much newer field of research than genetics, so this question perhaps would make a good question for Stack Exchange's Biology site.
Nonetheless, the idea of epigenetics giving magical abilities due to parents having environmental exposure to magic can still be valid: you could say the parents already had the genetic traits for magical ability existing in their DNA in an inactive state, and their magical abilities didn't manifest until the magical environment caused their epigenetics to activate the magic genes.