Possibly an interpretation of this phrase 'punishing the children for the sin of the parents to the third and fourth generation of those who hate me' will remove the questions you have. I am not sure whether you are questioning 'Why the children would be punished?' or 'Why parents would possibly go unpunished?' In either case this explanation will address both questions.
The context is the Old Testament under the Law of Moses. God through Moses saved Israel as slaves in Egypt and wants to take them to a land flowing with milk and honey to worship Him and be God's people. Worshiping idols would break that covenant, and He will spit them out from the land if they persist in that behaviour. (Leviticus Chapter 26 spells out the rules of this covenant very clearly). God will not allow them to stay in the land He was giving them if they practiced idolatry.
In Leviticus 26 God warns them that if under generation, after generation they still continued to break the covenant, then:
If in spite of this you still do not listen to me but continue to be hostile toward me, then in my anger I will be hostile toward you, and I myself will punish
you for your sins seven times over...Then the land will enjoy its sabbath years all the time that it lies desolate and you are in the country of your enemies; then the land will rest and enjoy its sabbaths. All the time that it lies desolate, the land will have the rest it did not have during the sabbaths you lived in it. (Leviticus 26:27-8;34-5)
Now the practice of idolatry and God throwing them out of the land during the Assyrian and Babylonian captivities are integral in making context of this phrase.
In the light of that context, we see that Israel practiced idolatry but God did not throw them out of the land for some generations later. I would not take the 'three generations' as being too strict for God might show mercy and extend the time of his judgments until later. This does not mean that the first generation that practiced idolatry would be without any punishment at all, it just means that as a nation, under national sins, God would not punish them immediately.
Second, it does not mean that God would punish the innocent, for if a generation would stop the practice, God would restore them and forgive them. The phrase implies 'persistence in sin' for 'generations'.
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
parents to the third and fourth generation of those who hate me, but
showing love to a thousand generations of those who love me and keep my
commandments. (NIV Exodus 20:5-6)
So what we are really talking about is this:
'Even though I will withhold deserved national punishment for those who
truly hate me, eventually possibly, three or four hundred years later,
I will still punish those persistent idolaters. Don't think while
generation follow generation in great wickedness that I will not
eventually lay down the hammer in a crushing blow!' (paraphrase)
Of course even in this scenario, for national judgments the innocent are involved along with the wicked. Even prophets were dragged off into exile for the sins of the previous generations.
If one is only trying to tally where does the generations begin and end, I think its a moot question, as this God can decide and alter as He wishes. The number of generations is not to be taken so literally from the context as explained.