In 1 Samuel 15, God tells Saul to kill the Amalekites because of something their ancestors had done. Just after the Exodus (if I had to guess a date, I'd guess 1280BC, but it could be as early as 1450BC), the Amalekites attacked Israel in the desert. But in about 1040BC, God says they will be punished for it. How can that be fair?
In Ezekiel 18, God says that he doesn't punish anyone for their ancestors' sins - people are punished for their own sins. But even then, there's the assumption that people normally follow their parents. Most people do what they saw their parents do. So if the parents are alcoholic or abusive, the children are more likely to grow up to be alcoholic or abusive. The parents' behaviour helps to explain why the child is like that, but it doesn't excuse it. People are still responsible for their own actions, and they can be judged for their parents' sins only when they themselves continue to walk in the way their parents walked, when they make their parents' sin their own.
The Amalekites were like that with attacking God's people. They had kept on doing it generation after generation - at least 5 times in the 250-odd years between the Exodus and Saul. The Amalekites as a nation are being judged because they keep attacking God's people, but individual Amalekites are judged based on their own actions.
You see, individual Amalekites have the chance to distance themselves from their nation (see Is there a way out for the Amalekites?). If they stay and fight, it shows they agree with the way their nation has acted.
There is evidence in the passage as well that individuals are judged for their own sin rather than the sin of their ancestors. In v18 they are described as "wicked people", and in v33 Agag is killed because his sword has made women childless.
God calls time on the Amalekites as a nation because of the actions of their ancestors, which they have continued in. But inidivdual Amalekites are judged for their own actions. If they distance themselves from their nation, they are spared.