For I, the LORD, your God, am a jealous God, inflicting punishment for their ancestors’ wickedness on the children of those who hate me, down to the third and fourth generation; but showing love down to the thousandth generation of those who love me and keep my commandments (Ex. 20:5-6).
The totality of Scripture condemns the idea that children are punished for the sins of the parents. The passage from Exodus on the surface appears to be contradicting that, and this misunderstanding was so prevalent that the prophet Ezekiel was forced to address it:
. . . What is the meaning of this proverb you recite in the land of Israel: “Parents eat sour grapes, but the children’s teeth are set on edge”?
As I live—oracle of the Lord GOD: I swear that none of you will ever repeat this proverb in Israel. For all life is mine: the life of the parent is like the life of the child, both are mine. Only the one who sins shall die! (Ez. 18:2-4).
But, in turn, if he begets a son who sees all the sins his father commits, yet fears and does not imitate him—a son who does not eat on the mountains, or raise his eyes to the idols of the house of Israel, or defile a neighbor’s wife; who does not oppress anyone, or exact a pledge, or commit robbery; who gives his food to the hungry and clothes the naked; who refrains from evildoing, accepts no interest or usury, but keeps my ordinances and walks in my statutes—this one shall not die for the sins of his father. He shall surely live! Only the father, since he committed extortion and robbed his brother, and did what was not good among his people—he will die because of his sin! (Ez. 18:14-18).
Exodus 20:5-6 is speaking of the consequences of breaking the commandment against false idols and other gods.
The commandments are not portrayed as arbitrary rules. The commandments are given as the path to true life and the fullness of life.
I have set before you life and death, the blessing and the curse. Choose life, then, that you and your descendants may live, by loving the LORD, your God, obeying his voice, and holding fast to him. For that will mean life for you, a long life for you to live on the land which the LORD swore to your ancestors, to Abraham, Isaac, and Jacob, to give to them (Deut. 30:19-20).
The message of the passage from Exodus is that the sins of the parents set a bad example for the children to follow. The parents will certainly experience negative consequences for their sins. The children seeing this bad example may follow it. If they follow this bad example, they too will experience these same consequences. And this bad example may be so ingrained in a family that it will last generations, and they will suffer these bad consequences as well. This passage from Exodus can be seen as a warning to parents that they not only possibly condemn themselves through their sins but that their bad example might condemn future generations.
The message of Scripture is that sin has more than just a personal consequence. Our sins affect not just ourselves but everyone around us.