Does God punish people for their ancestors' sins or not? Exodus 20:5 (NASB) says,

You shall not worship [idols] or serve them; for I, the Lord your God, am a jealous God, visiting the iniquity of the fathers on the children, on the third and the fourth generations of those who hate Me,

But Ezekiel 18:20 (NASB) says

The person who sins will die. The son will not bear the punishment for the father’s iniquity, nor will the father bear the punishment for the son’s iniquity; the righteousness of the righteous will be upon himself, and the wickedness of the wicked will be upon himself.

How are these two passages reconciled?
I believe you are asking two questions.  I'll answer the one in the heading first: 
Does God punish people for their ancestors' sins or not?

Yes, in the Christian traditions (majority of the denominations) God absolutely does "punish" the children of those who committed sin - else there would be no original sin.

1 Corinthians 15:22 KJV


  For as in Adam all die, even so in Christ shall all be made alive.


and 

Romans 5:12-21 KJV


  12 Wherefore, as by one man sin entered into the world, and death by
  sin; and so death passed upon all men, for that all have sinned:
  
  13 (For until the law sin was in the world: but sin is not imputed
  when there is no law.
  
  14 Nevertheless death reigned from Adam to Moses, even over them that
  had not sinned after the similitude of Adam's transgression, who is
  the figure of him that was to come.



The second question is: 

How can Exodus 20:5 and Ezekiel 18:20 be reconciled?

Reading the end of Ezekiel 18 explains it:

Ezekiel 18:30-32 NIV 


  30 “Therefore, you Israelites, I will judge each of you according to
  your own ways, declares the Sovereign Lord. Repent! Turn away from all
  your offenses; then sin will not be your downfall. 31 Rid yourselves
  of all the offenses you have committed, and get a new heart and a new
  spirit. Why will you die, people of Israel? 32 For I take no pleasure
  in the death of anyone, declares the Sovereign Lord. Repent and live!


Therefore, to repent and come to God will stop the inherited sin.  In a similar regard, mainstream Christianity teaches that believing in Jesus (thus repenting) will stop the cycle of sin (see original sin) and allow you to live.  Exactly what it means to "believe" in Jesus differs by denomination.

TLDR:

God punishes people for the previous generation's sin.  Repenting stops this cycle but doing nothing continues the sin's wrath.