Exodus 20:5 you shall not bow down to them nor serve them. For I, the LORD your God, am a jealous God, visiting the iniquity of the fathers on the children to the third and fourth generations of those who hate Me,
Exodus 34:7 Keeping mercy for thousands, forgiving iniquity and transgression and sin, and that will by no means clear the guilty; visiting the iniquity of the fathers upon the children, and upon the children’s children, unto the third and to the fourth generation.
Numbers 14:18 ‘The LORD is longsuffering and abundant in mercy, forgiving iniquity and transgression; but He by no means clears the guilty, visiting the iniquity of the fathers on the children to the third and fourth generation.’
Deuteronomy 5:9 you shall not bow down to them nor serve them. For I, the LORD your God, am a jealous God, visiting the iniquity of the fathers upon the children to the third and fourth generations of those who hate Me,
There is not a great deal to be gained in asking why God does or says ‘this’ instead of ‘that’. Unless God tells us why, any answer is going to be speculative. I can speculate the following:
There is a principle in the number three.
Deuteronomy 19:15… at the mouth of two witnesses, or at the mouth of three witnesses, shall the matter be established.
Ecclesiastes 4:12… a threefold cord is not quickly broken.
Matthew 18:16 But if he will not hear thee, then take with thee one or two more, that in the mouth of two or three witnesses every word may be established.
2 Corinthians 13:1 This is the third time I am coming to you. In the mouth of two or three witnesses shall every word be established.
There is a certain completeness in the number three. Three is used extensively in scripture.
'Three days' occurs 60 times and 'third day' occurs 50 times in the NKJV.
Israel were in Egypt for 3 generations and came out in the fourth.
Genesis 15:16 But in the fourth generation they shall come hither again: for the iniquity of the Amorites is not yet full.
Paul prayed three times that his ‘thorn’ might be removed and then ceased.
2 Corinthians 12:8 For this thing I besought the Lord thrice, that it might depart from me.
Peter had his vision repeated three times.
Acts 11:10 And this was done three times: and all were drawn up again into heaven.
Jesus’ ministry lasted three years; his death lasted three days. He will return in the third millennium from his first advent.
We might suppose that if the third generation continued in their hatred of God then a godless line has been fully established and retribution is just. God, being a merciful God, might delay the retribution until the fourth generation as an act of mercy.
God does not punish children for the sins of their fathers, but the children suffer the consequences of their father’s sins. We see this in the dispersion of the Jews from their homeland and the persecution they have endured - not for their own sins but because of their fathers’ failure to recognise their Messiah.
Matthew 27:25 And all the people answered and said, "His blood be on us and on our children." They have been removed from the land until the times of the gentiles are fulfilled.
We have an example of retribution on the fourth generation in the case of Jehu, anointed king of Israel and promised that his descendants would sit upon the throne to the fourth generation.
Jehu and his descendants kept the idolatry of the golden calves (as God knew they would) and were dethroned in the fourth generation.
In conclusion I think the emphasis is really upon three as a measure of fulness after which God might extend his mercy until the fourth.
Failure to act until the fifth or sixth would denote unnecessary procrastination.
I hope you find this helpful.