Exodus 20:4-6 seems pretty clear that God is intentionally punishing generations for their parents’ or grandparents' sins. However, in the story of Joseph, it makes it sound like God doesn't choose bad things to happen, but God is actually choosing to redeem them. It's confusing - and even upsetting - to consider that God chose the hurt to happen to us to punish our parents. Could you help me understand this verse better?
Thus is such a great question; and you're right, it is confusing. It gets right at the big question of: what kind of God do we worship anyway?
Here's my understanding. The first thing to understand is that people's understanding of God has changed over time. We can see this even in the Old Testament on this particular issue. Exodus 20 says, "I lay the sins of the parents upon their children."
But then go to Ezekiel 18, written hundreds of years later. The entire chapter's point is summarized in verse 20, "The one who sins is the one who will die. The child will not share the guilt of the parent, nor will the parent share the guilt of the child. The righteousness of the righteous will be credited to them, and the wickedness of the wicked will be charged against them."
So which one is it? Well, I think Ezekiel 18 gets closer to the truth. God cannot fully reveal God's self all at once. While God revealed much of God's character to Moses and the Israelites at Mt Sinai in Exodus, there was still much that the Israelites got wrong, misunderstood, or understood through their 12th century BCE filters.
It's not until we get to Jesus that we get the full revelation of what God is like. And when Jesus talks about God, Jesus says things like, "God shows kindness to the good and wicked alike," (Luke 6) and "God gives sunlight and rain on both the good and evil, the just and the unjust " (Matthew 5). In other words, God is always doing the most loving thing to all people, always.
So, no, God is not the punishing sort, and definitely not the sort who punishes others for someone else's mistakes.
I will add that modern family psychology has shown us that trauma/pain/sin can often beget more trauma/pain/sin in our families (cycles of alcoholism, abuse, etc.). We now have language to talk about that, and we don't have to drag God into it to explain how this works. But an ancient near eastern person may very well have thought that it was "the gods" intervening to inflict punishment on children.
That's not to say that the ancient near eastern person is somehow more primitive than we are. There are plenty of modern folks who still need to learn about patterns of trauma in family systems. Whereas an ancient person would very quickly understand why someone's great grandchild is repeating the same patterns of their ancestor.
I hope that helps!