I feel so guilty

I normally don’t have dreams i haven’t had a dream since I hit puberty, I have insomnia and rarely get good sleep. After my mom died and I had a miscarriage about 2.5 months ago I started taking an antihistamine at night and it helped so much with my sleep and consequently I started having dreams, A LOT. And my ex was always in them, usually incidentally, but for the last couple week they have been really sexual I had sex with him in this dream and I literally had an orgasm in my sleep, and I don’t know why.

So I dated him for about 9 months, I lost my virginity to him had sex with him once 4.5 years ago. He was the first person I dated after my fiancé passed away unexpectedly. I really fell for him fast, he was so nice kind we had a lot in common. But basically after we had sex he just slowly stopped talking to me when I went back home for summer break from school he just completely ignored me. He would randomly come in and out of my life for the year after that happened. Tell me he cares for basically just get me to talk to him for a while then stop and start, basically to just get me to have phone sex with him or send nudes. When I started talking to my husband I stopped all that, he would occasionally text me to see how I was doing and sometimes I’d answer I made sure he knew I was dating someone else so he wouldn’t ask for anything sexual and then he started bringing up the past about how he missed me and certain explicit things about me. After that I finally just blocked him because it was too much to deal with his bs and very clear he was just trying to use me despite me telling him I was in a relationship, and it wasn’t fair to me to keep letting him come in and out. I hadn’t talked to him in nearly three years and about 6 months ago a girl he dated far before me was stalking him and got my number kept texting me and made a statement about my fiancé who died.

So I texted my ex because I thought it was him because the chick said she was him, and I believed it she knew some stuff about our relationship but after she made that statement I didn’t think he’d say something that evil. She was batshit crazy, hacked into his phone and read all his texts he’s ever sent from his number, she’s in jail now for a few other things she did to him, sorry if this doesn’t make much sense and I know it’s all over the place I’m trying my best. But basically I talked to him when that was going down and he was trying to figure out who it was, but we haven’t talked since then.

Well anyway I’ve since married I have an almost two year old, I’ve been with my husband for 3.5 years, why the fuck am I having dreams about this asshole. I feel so guilty about these dreams I’ve mentioned them to my husband but not how much they bother me. I just feel so guilty about all this. I just want these dreams to stop but I also don’t want to stop taking my medication because I won’t be able sleep. Fuck please help me!!