TL;DR
The Church considered cremation as incompatible with the Christian tradition of burial (inherited from Judaism, and kept by Christians later on). This became particularly clear when secular cremation societies emerged in the 19th century. Hence the explicit prohibition in the Canon Law of 1917. Yet, as time went by, and as the practice became more popular, the Church realized cremation was commended by others not on anti-Cahtolic grounds, but on practical arguments (land use, cost, public health). Thus, it eliminated the restriction. However, there are limits to this freedom. As the Catechism (2301) states:
The Church permits cremation, provided that it does not demonstrate a denial of faith in the resurrection of the body.
This is, the person cremated must not have desired such method as a denial of an established Church dogma.
Long answer
The New Catholic Encyclopedia (2003) has a longish article about it. Here are some excerpts. First, some historical context:
The Hebrew Scriptures witness to the fact that the Israelites buried their
dead. The Gospel accounts describe how those who took
Jesus’ body from the cross were careful to observe Jewish burial practices as to time and manner of burial. Early Christians, even during the era of persecutions, maintained extensive cemeteries in Rome, North Africa, and elsewhere. Gradually Christian reverence for the body as a ‘‘temple of the Holy Spirit,’’ together with their belief in life after death, resurrection, and the immortality of the soul, reinforced the practice of inhumation. Through the Middle Ages into modern times cremation remained the exception, surfacing from time to time in circumstances of mass deaths from plagues, war, and natural disasters.
Then, in the 19th century, many cremation societies emerged in Europe and North America, usually arguing for it in terms of public hygiene and land conservation. Yet,
... the Church regarded the cremation societies as materialist and saw the practice as incompatible with the traditional burial customs of the Christian liturgy. In 1886 the Holy Office forbade Catholics from joining cremation societies and prohibited the practice of cremation. The 1917 Code of Canon Law did not address cremation as such but was sharply critical of the reasons used to justify it
(c. 1203). The 1917 Code also prohibited ecclesiastical burial of bodies that were to be cremated (c. 1240). Directives to missionaries outside Europe, however, were
milder in tone and allowed greater toleration of the practice [see Fonti (Fontes) CICO 4 n1189; 7n4905, Collectanea 2n1626]. Nonetheless, as late as 1926, an instruction
of the Holy Office still characterized proponents of cremation as ‘‘enemies of Christianity’’ and warned of the dangers of deemphasizing the resurrection of the body (AAS 18.282). These societies were perceived to be sectarian, hateful, and contrary to Catholic doctrine (c.1203).
Yet:
Responding to the changing pastoral needs brought
about by growth in the number of cremations, particularly
in Great Britain and Europe, the Holy See lifted the ban
on cremation. ... The lifting of the prohibition
reflected the reality that most proponents of cremation are
not motivated by anti-Catholic sentiment. The reasons
they give for cremation stress rather simplicity, sanitation, sound use of scarce land and, in North America, economic concerns.
Consequently,
the option to select cremation as a
means of final disposition was incorporated in the Ordo
Exsequiarum for the universal Church of the Roman Rite
(1969) and in funeral rites for English-speaking countries
(The Rite of Funerals 1970–1989). The 1983 revision of
the Code of Canon Law (c. 1176) codified the authorization and liturgical law. According to the revised law, good will among the faithful is presumed. Cremation and interment both are subject to the same criterion: that Catholic faith and liturgical practice guide and direct pastoral care at the time of death.
Importantly, it is still suggested that the body be present at the funeral. I.e. that cremation occurs after the funeral:
‘‘The Church clearly prefers and urges that the
body of the deceased be present for the funeral rites, since
the presence of the human body better expresses the values which the Church affirms in those rites.’’ Cremation
and Committal of the Remains before the Funeral Liturgy
(OCF, 422–425).
Moreover, the Church is not sympathetic to "spreading the ashes" in nature, nor with its private keeping:
Liturgical tradition and the role the Catholic cemetery plays in preserving the memory of Christians profess explicit belief in the promise of resurrection. The cremation Appendix to the OCF expresses
the clear preference for preserving the remains of loved
ones by interment in a tomb or preservation in a columbarium. ‘‘The practice of scattering cremated remains on
the sea, from the air, or on the ground, or keeping cremated remains in the home of a relative or friend of the deceased, are not the reverent disposition that the Church
requires’’ (OCF, 417).
Finally:
The Catechism of the Catholic Church, citing canon 1176, makes the simple
statement, ‘‘The Church permits cremation, provided that
it does not demonstrate a denial of faith in the resurrection of the body’’ (n. 2301). Christian belief in the resurrection of the dead is in no way affected by the state of
the corporeal remains. This has been the clearly articulated teaching of the Catholic Church throughout the history of the cremation controversy in the 19th century.