Is it legal in Islam to exhume graves? If so, under what conditions? How should the remains be handled? What are the rules for the re-burial of remains?
By default exhuming human remains is forbidden because it is disrespectful to the deceased, hurtful to their family and considered abhorent by human nature.
It is only permitted when there is a valid reason for it, i.e. if the right of someone is associated with it.
If something valuable fell and was left in the grave, then it is permitted to recover it.
If the deceased was wrapped in an usurped burial shroud then it is permitted to recover it.
If the land of the grave was usurped then it is permitted to relocate the body.
If it is discovered that the deceased was a pregnant woman and there is chance that her child is alive, then it is permitted to attempt to save their life. There is difference of opinion on this.
If some ritual was omitted such as bathing, shrouding, funeral prayer etc. then it is permitted to exhume the body and make corrections. There is difference of opinion on this.
If the intention is to transfer the body for burial at a better place. There is difference of opinion on this.
In the cases where it is permitted, scholars apply the condition that the experts of the area should be of the opinion that the body will not have started decaying yet. Similarly they apply the condition that person (whose right was violated) should be insisting on return of their property and alternative compensation should either have been refused or not be possible.
Remains of a deceased person have the same sanctity as when alive so they should be handled with care and should be promptly reburied. There are no unique rituals or rules associated with reburial.