Deut. 5:9 You shall not bow down to them or worship them; for I, the LORD your God, am a jealous God, punishing the children for the sin of the fathers to the third and fourth generation of those who hate me...
First of all, please keep in mind the Constitution of the Mosaic Law was only for one nation, only for the nation of ancient Israel.
Please see Exodus chapter 20 the first ten of over 600 commandments.
Deut. 5:9 is in connection to false worship ( idol worship - bow down ) as also earlier mentioned at Exodus 20 vs 4-6; 34 vs 4-7
Those particular Israelites were showing hatred toward God by their idol worship. ' those who hate me '
An example comes to mind was wicked king Manassah.
Although Manassah did finally repent, when his son Amon became king he followed the former idol-worship course of his father.
Then, Amon's grandsons and great grandson none of them showed love for God.
Because the parent set up false idol worship then likely succeeding generations likely followed in his footsteps.
Then, they reaped the bad outcome ( punishment ) of their idolatrous course they chose.
Even today a drugged parent can pass on defects ( punishment ) to the next generations because they reap what they sowed.
So, Not meaning punishment as we might think of discipline today, but punishment in that the ill effects of wrongdoing can affect the next few generations. So, one's actions good or bad can bring rewards or punishments upon the next generations.
There are always extenuating circumstances, but for the sake of illustration:
A thrifty grandfather might set aside a nice inheritance for his son and grandson, whereas a greedy grandfather might squander his money leaving nothing to sons or grandsons. The ' punishment ', so to speak, in that case would make life harder for that next generation. On the other hand, the blessing from the thrifty grandfather could make an easier start in life for the son or grandson.
It was God's love for the faithful ' forefathers ' why God had the Exodus and delivered the people out of Egypt - Deut. 4:37
Those who choose to do what is right, then God shows His loyal love to the ' thousandth generation ' of those who love Him and keep His commandments - Exodus 20:6; Deut. 5:10
The word ' father ' means: life giver.
Because Jesus is given the power of the resurrection - Rev. 1:18 - then Jesus will be ' eternal father ' to resurrected ones.
Only those individuals of Matthew 12:32; Hebrews 6:4-6 will Not have the benefits of Jesus' resurrection power.