It is an interesting topic and a scholar is appropriate to answer regarding Quran’s stance.
I just want to share my thoughts on this topic. I think it is both possible that brain is making up dreams out of memories or the actual person is trying to communicate. What I have read so far from religious perspective, it seems unlikely that a deceased person is trying to communicate through dreams.
I wish someone would have tested it to prove this. I came up with an experiment long time ago from my university time but I was not able to complete it.
Basically give a terminally ill person a few envolop with sequential numbers on the outside. For example envelope numbered 1 to 10 for 10 envelops. Ask the terminally ill person to privately write random 3 digit numbers on 10 pieces of paper and insert in each envelop and seal the envelops so only the dying person knows those numbers.
Now after the person’s death if a relative sees a dream where the person sees 3 digit number in the dream, they should open the first envelop to check if the number matches. If the number in the dream and in the envelop matches, then it is a proof that decesed can communicate after death. Also this system can be used to distinguish between true dreams where deceased is trying to communicate and dreams made up by our subconscious mind.