Praise be to Allah, and peace and blessings be upon the Messenger of Allah. To proceed:
When a person dies, they enter the realm of Barzakh, which is a world different from this worldly life. Their soul does not return to their family or to their home. The claim that the soul remains for forty days or returns to the place where the person died has no basis in the Qur'an or the authentic Sunnah. Rather, it is one of the widespread myths and popular beliefs.
The basic principle is that the deceased has left the life of this world and is occupied with the bliss or punishment of the Barzakh. Therefore, they do not have unrestricted knowledge of the conditions of their family.
Some reports indicate that Allah may allow certain deceased people to know something about the condition of their relatives. However, these reports are not sufficient to establish a religious ruling. Therefore, it is not permissible to state with certainty that the deceased know everything their families do or constantly watch over them.
Seeing a deceased person in a dream may be true, or it may simply be a product of one's thoughts or the deception of Satan.
For this reason, Islamic beliefs and religious rulings must not be based on dreams, even if the deceased appears to speak or leave advice, unless what is seen agrees with what has already been established in the Islamic texts.
A person may indeed have a truthful dream in which they see the deceased, but this remains a probable matter rather than something certain. It depends on the truthfulness of the dreamer and the authenticity of the dream, and it cannot be relied upon to establish matters of the unseen.
The soul of the deceased does not return to their home or family after death, and there is no authentic evidence that it remains for forty days in the place where the person died. The deceased remains in the realm of the Barzakh. Allah may allow some deceased people to know certain things about their families, but this is neither general nor firmly established. As for seeing the deceased in dreams, some dreams may be true while others are not, so dreams cannot be used as a basis for Islamic beliefs or religious rulings.
And Allah knows best.