There are several instances in the Old Testament of people misunderstanding God on this matter. The misunderstanding originated long before the Ten Commandments were set in stone, where that bit about the sins of fathers is contained. Way back in the time of Job, he is recorded as quoting the saying, that "God stores up a man's punishment for his sons.' (Job 21:19) Job knew what his supposed comforters were thinking about the rash of disasters that came on him, his family, and his wealth, maintaining in face of their implications that he had not sinned so as to "deserve" such suffering.
Later on, God had this recorded in the Ten Commandments, but it is essential to quote the entire pertinent bit, if we are not to misunderstand. Here is the relevant part:
"Thou shalt not bow down to [idols], nor serve them: for I the Lord
thy God am a jealous God, visiting the iniquity of the fathers upon
the children unto the third and fourth generations of them that
hate me, and shewing mercy unto thousands of them that love me and
keep my commandments." Deuteronomy 5:9-10 A.V. Bold emphasis mine.
It's interesting that Young's literal translation has 'zealous' for 'jealous', and has square brackets round 'generation'. If the meaning is three or four sons suffering for the iniquity of their fathers who hate the Lord, that would fit in with the next bit speaking of God showing mercy to thousands. It would also follow that any son who loves the Lord and who obeys his commands would be shown mercy by God. That fits in with Ezekiel 18 saying that the soul who sins will die, not the children of fathers who hate the Lord. Of course, it must be remembered that fathers who hate and who disobey God are likely to bring their sons up to do the same. Yet where a son loves and obeys God, mercy will be shown, as Deuteronomy 5:10 states. This means there is no contradiction.
This also fits in with what the prophet Jeremiah wrote in the Old Testament, and what Daniel also said:
"You show love to thousands but bring the punishment for the fathers'
sins into the laps of their children after them... You reward everyone
according to his conduct and as his deeds deserve." Jeremiah 32:18-19
"O Lord, the great and awesome God who keeps his covenant of love with
all who live him and obey his commands." Daniel 9:4 N.I.V.
It's strange how many people can latch on like limpets to bits about punishing children, without balancing that with the related fact of God's overwhelming love and mercy. Thousands receive his love and mercy; three or four suffer dire consequences of hating and disobeying him. This also has to do with the biblical principle of reaping what we sow (Hosea 8:7). There are consequences for the children of fathers who hate and disobey God. Yet any such children who turn to God in love and obedience will receive God's love and mercy! This is the connecting fact between all such scriptures, which keeps getting missed.