Ashwatthama threw Brahmastra on the wombs of Pandava women.
https://www.sacred-texts.com/hin/m10/m10015.htm
Vaishampayana continued, "The son of Drona, having heard these words of the island-born, threw that uplifted weapon into the wombs of the Pandava women."
https://www.sacred-texts.com/hin/m10/m10016.htm
Here, Krishna explains why he curses Ashwatthama.
The holy one said, "The fall of this mighty weapon will not be fruitless. The foetus will die. But being dead, it will live again and have a long life! As regards thyself, all wise men know thee for a coward and a sinful wretch! Always engaged in sinful acts, thou art the slayer of children. For this reason, thou must have to bear the fruit of these thy sins. For 3,000 years thou shalt wander over this earth, without a companion and without being able to talk with anyone. Alone and without anybody by thy side, thou shalt wander through diverse countries, O wretch, thou shalt have no place in the midst of men. The stench of pus and blood shall emanate from thee, and inaccessible forests and dreary moors shall be thy abode! Thou shalt wander over the Earth, O thou of sinful soul, with the weight of all diseases on thee.
Then, Vyasa also tells him that these words will be true.
Vyasa said, "Since, disregarding us, thou hast perpetrated this exceedingly cruel act, and since thy behaviour is such although thou art a good brahmana (by birth), therefore, those excellent words that Devaki's son has said, will, without doubt, be realised in thy case, an adopter as thou hast been of kshatriya usages!"