How does one understand it in the context that God is just and illegitimate children are not personally guilty of the circumstances of their conception?
I haven’t spent much time on that verse but here are a few thoughts off the top of my head:
It doesn’t speak of any guilt passed to child due to sins of a parent; it only lays down a rule restricting same. Not saying it’s good news for the person affected, just that it’s not the same as guilt.
We must use care whenever exploring laws, regulations and curses set forth in the Old Testament. Remember, the law was “added because of transgressions,” and acted as a “schoolmaster” of sorts, as St. Paul explains. Israel turned away from God (broke the covenant and worshiped false gods) over and over. They would be burdened by more restrictive regulations to teach a lesson and make a point.
All OT history, ceremonial laws, prophecy, MUST be seen in light of God’s promise of a NEW and better covenant! After all these terrible laws and punishments (Duet, Lev, Kings), the prophets warned Israel to repent (Isa, Jer, Ez) and pointed to a day when God would give a new covenant that would bring peace, forgiveness and freedom to God’s people. Thanks be to God, we are living in that covenant relationship now! Hallelujah.
The next day, John saw Jesus coming to him, and he saith: Behold the Lamb of God, behold him who taketh away the sin of the world. (John 1:29)
Remember that we are a wicked and fallen race, so God has to lead us a few steps at a time.