Comfort after a miscarriage:
The Rebbe once wrote to a couple who suffered a miscarriage that many great Torah giants were born after a miscarriage, and they should therefore not be discouraged.
A portion in the world to come and in the future resurrection: Even a fetus which was not carried to term has a portion in the world to come, as the fetus received a soul the moment of conception, and this soul will merit resurrection in the future world. In fact, they will be resurrected as complete Tzaddikim, as these souls never had the opportunity to sin. Accordingly, even if a fetus is not carried to term, it plays an important role in hastening the coming redemption which is dependent on the descent of all the souls that are found in the storage room of souls in heaven.___________________________________________________
 Igros Kodesh 29:30
 See Sanhedrin 110b; Rashi ibid; Pischeiy Megadim 38; Nitei Gavriel 112:19 footnote 22