“‘The Lord is slow to anger and abounding in steadfast love, forgiving iniquity and transgression, but he will by no means clear the guilty, visiting the iniquity of the fathers on the children, to the third and the fourth generation.’” Numbers 14:18
“The soul who sins shall die. The son shall not suffer for the iniquity of the father, nor the father suffer for the iniquity of the son. The righteousness of the righteous shall be upon himself, and the wickedness of the wicked shall be upon himself.” Ezekiel 18:20
These verses represent a huge area of study that is debated among good biblical scholars and can’t be answered well in just a few short sentences. Having said this, my short answer would be: No, these are not contradictory at all but are saying two separate but related things.
The Numbers verse and verses like it are revealing that God is just and we ought to revere him and not do evil, because God might just discipline us by disciplining us, and our children or children’s children may suffer. The punishment is felt by and is meant for the parents. It’s a warning for parents and grandparents not to sin, because our children and grandchildren may suffer consequences for it. In other words, God does as he pleases in enacting justice and discipline, and my sin doesn’t just affect me.
The Ezekiel verse is to remind us again, that God is just, but for another reason. God’s people in Ezekiel’s day were not taking responsibility for their circumstances. Likewise, if our circumstances are bad, we’re not just able to blame our parents for it and do nothing. We are not responsible for our parents sin, even though we may suffer the consequences. Their sin is their sin. But we are however very responsible for what we ourselves do.
In both cases we are being taught to believe that God is in charge, and he enacts his discipline and justice in the world today and now, and does so fairly, because he is God and everything he does is good whether we understand it or not. We can be sure that sin affects us and others and that God is doing something about it. We ought to repent of our own personal sin, and protect future generations from any collateral damage.