Sometimes this is done to retrieve relics, among other things.
It seems scandalous to many modern folks, but the Christian church was notorious among the ancients for scrupulously caring for the dying and the dead, even for the bodies of non-believers. This caring for the bodies of others was an act of selfless charity which was noticed by the pagan neighbors. This in concert with the very ancient Christian belief that creation is fundamentally good, the human body is good (not a bad or evil thing as many gnostic heretics taught), that we can look forward (or maybe with a sense of dread, for some of us

) to life eternal and a restoration of the body to the soul. This was a radically different attitude than was common in those days, since the few belief systems that actually contemplated an afterlife often taught that the body was a trap for the soul, to be escaped and abandoned.
The burial sites (and death sites) of martyrs and other holy individuals usually attracted visitors, some I suppose were very pious and some may have had a morbid curiosity, but these locations frequently became places of prayer and worship, especially on the anniversary of a martyrdom (like a birthday, one is reborn in Christ and baptised in blood at a martyrdom) with eventually significant church buildings raised over the site. This is the origin of the practice of placing a relic of a saint into or under an altar, and the naming of church buildings after saints.
Saint Peter’s basilica is probably the best known of these sites, it is not actually the cathedral of Rome, the original structure (now long gone) was actually constructed with public funds over a cemetary by order of Saint Constantine the emperor. The top of the hill was chopped down and used for landfill in the lower spots, but the altar was located above the grave of Saint Peter.
For whatever reason, due to construction or for who knows what, early Christians sometimes were amazed to discover the remains of an individual (especially important in the case of a suspected holy person) were still recognizeable, perhaps even lifelike, after many years of entombment. Some people took it as a sign. This is not an Apostolic Teaching, we have no evidence that Jesus Christ or the Apostles ever taught on this subject.
IMO, the incorruptable claim is rather overdone, many (if not most, or even all) such claims have continued to deteriorate after discovery. The manner of death sometimes affects the outcome, as well as the preparation of the corpse and the site chosen can be factors.