Loss
Below we quote Freud verbatim to explain what the work of mourning consists of:
The examination of reality has shown that the beloved object no longer exists and from it now emanates the exhortation to remove all libido with the links of that object. An understandable renunciation opposes it, that renunciation can reach such intensity that it produces an estrangement from reality and a retention of the object by means of a hallucinatory psychosis of desire.
Thus reality shows us that the object is no longer there, either because it has died or because the situation that gives us comfort can no longer continue (work, couples, freedom, ideals). One becomes very reluctant to accept the loss (tolerance to frustration) and we begin to deny and reject it, one tries to choose the estrangement from reality, that is, stop seeing reality and satisfy the need for the object to be a hallucinatory form.
The unresolved duel
The normal thing for Freud is that once the work of mourning has been completed, the self becomes free again, that is, the libido that had been deposited in the object is withdrawn (for example, energy is withdrawn from lost employment, to the old loving couple). So the mourning process involves realizing that the object is no longer there, all the libido put on the object is taken out, the self is put on, and so then release that libido again in another object.
This is the explanation that Freud offers, and it is at this point that the difference between mourning and melancholy is observed, since the problem with melancholy is that it is an extended mourning.
Freud said that the neurotic subject knows who he lost but does not know what he lost in him, so it is understood then that melancholy is an unconscious loss.
What happens in melancholy is that all that libido (energy) that remained floating when the object was lost, returns to the self and absorbs it, thus begins narcissism that is also part of Freud's theory. On the other hand, in the duel, when this is resolved, the libido returns once more to the objects. (For example, where others see that a person is going through a process of mourning and has no interest in things or events that - normally - would attract their attention: going out with friends, working, playing sports. Other people can observe him as something abnormal or atypical but as they finally relate it to the recent loss and come to consider it normal "it is normal that it is so because of the loss of ...").