Reference: ‘Ishratun-Nisaa. wa Hill al-Khilaafaat az-Zowjiyyah – Page 57
Question: I slept next to my wife and saw in my dream that I was having sexual intercourse, and as a result, I ejaculated sperm. So when I awoke from my dream I washed myself and went to my wife and had sexual intercourse with her. So is there any sin upon me or not?
Response: If the situation is as you have described, then there is no sin upon you with respect to the dream, rather it is upon you to take a ghusl as a result.
Likewise, it is upon you to take a ghusl for a second time after having had sexual intercourse with your wife.
However, if you delayed taking a ghusl as a result of the dream until you had sexual intercourse with you wife, and then took a ghusl for them both (the dream and sexual intercourse with the wife), then there is no harm in this.
And with Allaah lies all success and may Allaah send prayers and salutations upon our Prophet ﷺ and his family and his companions.