It should be said that it is related. It's just that this relationship is very weak. Whether you learn math well or not is related to the structure of your brain. People with developed brains will naturally learn a lot easier. But for most people, there is not much difference in brain structure, so we still have to rely on our own efforts.
Poor parents' math doesn't mean poor parents' genes, and parents' genes can't determine children's genes.