It's...complicated. Fortunately, Tolkien wrote about this extensively in an essay titled "Laws and Customs Among the Eldar".
To summarize:
- Their soul gets separated from its body, and invited to Aman and the Halls of Mandos
- If it returns to Mandos, it spends a period of time in a purgatory-like state, before possibly (at the discretion of the Vala Mandos and at their own choice) re-born into a new body
- If they refuse the summons, they haunt the incarnate world as ghosts
What does "death" mean for Tolkien's Elves?
It seems a little bit silly to talk about Elvish death in the first place, since the Elves are frequently described as immortal, a word which literally means "not susceptible to death." However, to Tolkien, Elves aren't really immortal; they're functionally immortal, but the natural span of their lives is not actually infinite:
[T]he Eldar do indeed grow older, even if slowly: the limit of their lives is the life of Arda, which though long beyond the reckoning of Men is not endless, and ages also.
History of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar
"Death", therefore, is the unnatural span of an Elf's life: Tolkien defines it more precisely as the separation of feä (spirit, or soul) and hroä (body):
Now the Eldar are immortal within Arda according to their right nature. But if a feä (or spirit) indwells in and coheres with a [hroä] (or bodily form) that is not of its own choice but ordained, and is made of the flesh or substance of Arda itself, then the fortune of this union must be vulnerable by the evils that do hurt to Arda.
[...]
If then the [hroä] be destroyed, or so hurt that it ceases to have health, sooner or later it 'dies'. That is: it becomes painful for the feä to dwell in it, being neither a help to life and will nor a delight to use, so that the feä departs from it, and its function being at an end its coherence is unloosed, and it returns again to the general [body] of Arda. Then the feä is, as it were, houseless, and it becomes invisible to bodily eyes (though clearly perceptible by direct awareness to other feär).
History of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar
What happens to an Elf who dies?
As above, their spirit becomes "unhoused". That's when things get interesting:
Those feär, therefore, that in the marring of Arda suffered unnaturally a divorce from their [hroä] remained still in Arda and in Time. But in this state they were open to the direct instruction and command of the Valar. As soon as they were disbodied they were summoned to leave the places of their life and death and go to the 'Halls of Waiting': Mandos, in the realm of the Valar.
If they obeyed this summons different opportunities lay before them. The length of time that they dwelt in Waiting was partly at the will of Námo the Judge, lord of Mandos, partly at their own will. The happiest fortune, [the Elves] deemed, was after the Waiting to be re-born, for so the evil and grief that they had suffered in the curtailment of their natural course might be redressed.
History of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar
Basically, the houseless Elvish feär are invited to return to Aman. If they do so, they get a period in purgatory and, eventually, if they desire it, reborn in Aman. In exactly one case, an Elf was re-embodied and then returned to Middle-earth; but that's an exceptional case.
However, not all feär in Mandos are reborn; some of them did not wish to return to life, and a small number (Feänor chief among them) did such bad things in life that they were not permitted rebirth).
Are Elves reborn into their old bodies, or do they get new ones?
Tolkien is unclear on this. In "Laws and Customs", he suggests that, in the vast majority of cases, Elves are reborn through childbirth, and therefore get new bodies:
A houseless feä that chose or was permitted to return to life re-entered the incarnate world through child-birth. Only thus could it return. For it is plain that the provision of a bodily house for a feä, and the union of feä with [hroä], was committed by Eru to the Children, to be achieved in the act of begetting.
History of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar
He suggests that it's possible for an Elf to be reborn into their old body, but it's rare; the old body would need to be perfectly preserved and undamaged, which is an unlikely occurrence.
However, "Laws and Customs" was not Tolkien's last word on the subject; Christopher Tolkien discusses his father's changing view on the subject in an appendix on "Athrabeth Finrod ah Andreth"; in particular he reproduces part of a discussion between Manwë and Eru:
Manwë spoke to Eru, saying: 'Behold! an evil appears in Arda that we did not look for: the First-born Children, whom Thou madest immortal, suffer now severance of spirit and body. Many of the feär of the Elves in Middle-earth are now houseless; and even in Aman there is one. The houseless we summon to Aman, to keep them from the Darkness, and all who hear our voice abide here in waiting. What further is to be done? Is there no means by which their lives may be renewed, to follow the courses which Thou hast designed? And what of the bereaved who mourn those that have gone?'
Eru answered: 'Let the houseless be re-housed!'
Manwë asked: 'How shall this be done?'
Eru answered: 'Let the body that was destroyed be re-made. Or let the naked feä be re-born as a child.'
History of Middle-earth X Morgoth's Ring Part 4: "Athrabeth Finrod ah Andreth" Appendix "'The Converse of Manwë and Eru' and later conceptions of Elvish reincarnation
According to this version, an Elf may be reborn either in a new body, or their old body may be recreated for them; which one is at the discretion of the Valar (presumably meaning Mandos).
However, Tolkien's final word was that the Elves were reincarnated either into their original bodies (if it was available) or into exact recreations of their original bodies; Christopher Tolkien devotes a good portion of the appendix describing how Tolkien came to this conclusion, but the final word on the matter comes from a note on "Athrebeth":
They were given the choice to remain houseless, or (if they wished) to be re-housed in the same form and shape as they had had. Normally they must nonetheless remain in Aman.
History of Middle-earth X Morgoth's Ring Part 4: "Athrabeth Finrod ah Andreth" Appendix "'The Converse of Manwë and Eru' and later conceptions of Elvish reincarnation
What about feär that refuse the summons?
Astute readers will note something about one of my quotes above (emphasis mine):
If they obeyed this summons different opportunities lay before them. [...]
History of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar
As implied, it is entirely possible for a feä to ignore the summons of the Valar, although that reflects rather poorly on the Elf who does so. The result of that choice is also described:
[I]t would seem that in these after-days more and more of the Elves, be they of the Eldalië in origin or be they of other kinds, who linger in Middle-earth now refuse the summons of Mandos, and wander houseless in the world, unwilling to leave it and unwilling to inhabit it, haunting trees or springs or hidden places that once they knew.
History of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar
These Elves essentially becomes ghosts; some are dangerous, and willing to try to "steal" bodies from the living:
Some say that the Houseless desire bodies, though they are not willing to seek them lawfully by submission to the judgement of Mandos. The wicked among them will take bodies, if they can, unlawfully. The peril of communing with them is, therefore, not only the peril of being deluded by fantasies or lies: there is peril also of destruction. FOr one of the hungry Houseless, if it is admitted to the friendship of the Living, may seek to eject the feä from its body; and in the contest for mastery the body may be gravely injured, even if it be not wrested from its rightful habitant. Or the Houseless may plead for shelter, and if it is admitted, then will seek to enslave its host and use both his will and his body for its own purposes.
History of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar
What about Elves who lose the will to live?
In most cases, they simply die of their own volition, and their fate is no different to any other Elf who dies. Elves are able to will themselves to die, and this typically only occurs in Elves who "gave up hope":
[S]ome feär in grief or weariness gave up hope, and turning away from life relinquished their bodies, even though these might have been healed or were indeed unhurt. Few of these latter desired to be re-born, not at least until they had been long in 'waiting'; some never returned.
History of Middle-earth X Morgoth's Ring Part 3: "The Later Quenta Silmarillion" Chapter 2: "The Second Phase" Laws and Customs Among the Eldar
In principle there's no reason why an Elf in Middle-earth who had given up hope couldn't simply take a ship over the Sea, rather than choosing to die, but I'm not aware of any examples off-hand.
The closest I can think of is Celebrían, the wife of Elrond, who left Middle-earth after being captured by Orcs:
In 2509 Celebrían wife of Elrond was journeying to Lórien when she was waylaid in the Redhorn Pass, and her escort being scattered by the sudden assault of the Orcs, she was seized and carried off. She was pursued and rescued by Elladan and Elrohir, but not before she had suffered torment and had received a poisoned wound. She was brought back to Imladris, and though healed in body by Elrond, lost all delight in Middle-earth, and the next year went to the Havens and passed over Sea.
Return of the King Appendix A "Annals of the Kings and Rulers" Part 1: "The Númenórean Kings" (iii) Eriador, Arnor, and the Heirs of Isildur The North-Kingdom and the Dúnedain
It's not clear that she actually lost the will to live, in the strictest sense, but does indicate that Elves suffering from mental health problems (e.g. depression after being held captive by Orcs) can depart over the Sea for healing, rather than simply giving up life.