Praise be to Allah.
In the answer to question no. 42384 we stated that it is permissible to give charity on behalf of the deceased. In the answer to question no. 157073 we spoke of some dreams which apparently indicate that the deceased is in need of something from the living that will benefit him, such as du‘aa’, charity on his behalf, paying off debts, and so on.
In these two cases, there is nothing wrong with giving charity on behalf of the deceased on one’s own intiative, and giving charity on his behalf if the apparent meaning of the dream suggests that he is in need of charity (being done on his behalf).
But as for believing that merely seeing the deceased in a dream means that it is obligatory or encouraged to give charity on his behalf, there is no basis or evidence for that; rather it is more akin to innovation (bid‘ah).
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) was asked about someone who saw someone in a dream, such as a paternal uncle, grandfather or maternal uncle, and so on; does he have to give charity on behalf of the person he saw in his dream?
He (may Allah have mercy on him) replied: He does not have to give charity on behalf of the deceased if he sees him in his dream, no matter what state he appeared to be in (in the dream); rather; if he sees the deceased in a state that makes him happy, then this is good for him and he may tell those whom he loves about it. But if he sees him in an upsetting state, then what is prescribed for the one who sees something that upsets him in his dream is to seek refuge with Allah from the accursed Shaytaan and the evil of what he has seen, to spit dryly to his left three times, and to turn over onto the other side, and not to tell anyone about that. If he sees that again in his dream, then he should get up, spit dryly to his left three times, seek refuge with Allah from its evil and from the evil of what he has seen and from the evil of the Shaytaan, remember Allah, and do wudoo’ and pray, to rid himself of that dream in which he saw something that upset him. That is because the Shaytaan may take on a form that upsets him and fill him with worry and distress. Allah, may He be blessed and exalted, has told us of how the Shaytaan loves to upset people, as He says (interpretation of the meaning): “Secret counsels (conspiracies) are only from Shaytan (Satan), in order that he may cause grief to the believers” [al-Mujaadilah 58:10]. This indicates that the Shaytaan is keen to do anything that may cause grief to people, make them anxious and fill them with worry and distress.
End quote from Fataawa Noor ‘ala ad-Darb by Ibn ‘Uthaymeen
And Allah knows best.