You have part of your answer in Ezekiel 18, which you quote. Verses 5-9 describe a righteous man. Verses 10-13 describe that man’s wicked son. They conclude by telling us that the son will be put to death for his sins and not receive any leniency on account of his father’s good deeds.
Thus the good deeds are not inherited.
The Bible does teach that we are made in the image of God. There is part of the original goodness of our nature that persists and is passed down. It is debated even among those who believe in original sin whether it is just an inclination to sin (a sin nature) that is inherited or actual, transferable guilt.
Exodus 34:6-7 says this:
And he passed in front of Moses, proclaiming, “The LORD, the LORD, the
compassionate and gracious God, slow to anger, abounding in love and
faithfulness, maintaining love to thousands, and forgiving wickedness,
rebellion and sin. Yet he does not leave the guilty unpunished; he
punishes the children and their children for the sin of the parents to
the third and fourth generation.” (Exodus 34:6-7, NIV)
It is fascinating that modern science has proven this verse true. Behavioral traits based on a response to the environment are passed down via epigenetic expression. However, if the stimuli that induced the response disappear from the environment, the effect upon later generations steadily diminishes. This is like things go with alcoholism. The children of alcoholics have strong negative traits, grandchildren of alcoholics have lesser expressions, etc. Those descendants are not guilty of the alcoholic offenses (unless they become alcoholics themselves) but they suffer ill effects due to their parent’s or grandparent’s actions.
What we as humans must NOT do is persecute the children in law or custom by imputing legal guilt to the children of criminals. This is called corruption of blood. Rights, privileges and property could be seized from whole families on account of a family member’s actions. Abolishing this was one goal of the American revolution. It took numerous bills in England during the 19th century to abolish this practice in stages. Even so, it has been creeping back in the form of punitive civil forfeiture laws.
To conclude, it is for God to deal with our inherited sin nature through salvation and spiritual regeneration, not human courts. Human courts are to punish individuals only for acts they commit.