This misunderstanding stems from the book of Exodus:
“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.
However, we know that virtually every part of Scripture condemns the idea that an innocent child could be punished for the sins of their parents. Even though the passage above seems to be leaning that way, it was actually condemning the worship of idols. The Lord wants to show the seriousness of choosing to bow to idols than worship him. However, he speaks through Ezekiel to show the nature of sin; it is nontransferable and in this sense personal. The Prophet Ezekiel says:
“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).
If a parent sets a bad example for their children and the latter follow in their footsteps, they will be punished alongside their parents. A family could have a tradition of sin beginning from the sins of an ancestor who sets a bad example for their children, however, each person is choosing to freely practice or reject sinful traditions or behaviors. Those who choose to continue a sinful tradition incurs the same consequences as their parents, but those who reject them are free and are not punished. God does not punish anyone for any sins they didn’t commit.
God gives the commandments as a path to 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).