This Is My Faith - Al-fatlawi, Ali - الصفحة ١٢٥ - Is Happiness and Misery from Allah?
beings are of two types: one is born from sperms and eggs of healthy parents physically and spiritually; this type is described with a happiness that will stay for all life along. The other one is born from a sperm and an ovum of unhealthy parents physically and spiritually; this type is doomed with unhappiness ‘unless your Lord wills otherwise’. So, this is related to this life and not the afterlife.
There is actually another Hadith that gives explanation to this Prophetic Hadith:
Hamad Bin Omair said: I asked Musa Bin Ja’far (PBUH) about the implication of the Prophetic Hadith “An unhappy person turns unhappy in his mother’s womb and a happy person turns happy in his mother’s womb”. He replied: The unhappy person is the one that Allah knows since he is still in his mother womb that he will be acting unhappily and the happy person is the one that Allah knows since he is still in his mother womb that he will be acting happily.
Thus, happiness and unhappiness of people since they are still in their mothers’ bellies implies God’s knowledge of man’s happiness and unhappiness due to