He knows what you did, but he doesn't know why you did it. It's not gaslighting, but it's nasty, argumentative and exhausting!
Why not try saying to him that you won't be drawn into pointless arguments about what you are thinking? You could say you don't make assumptions about what is going on in his head and you won't engage when he does it to you.
My DH can happily run both sides of an argument when he gets going, filling in what he thinks I'm thinking, and I tell him what he's doing leave him to it - he doesn't need me.
When he says, "I know exactly why you did that, it was because of x," the only sane response is,
"If you want to know what I'm actually thinking, you can ask me and I'll tell you."
The corollary, of course, is; "It looks as if you'd rather run both sides of the argument yourself, role-playing at being me. I'll leave you to it because you don't need the real me here for that and I have more interesting things to do than be your audience."
You might have to keep the second part for when he's calmed down!
But truly, don't get drawn in to arguing with him if he's trying to tell you what you're thinking. That's never going anywhere good. He's not a mind-reader. We use words to ask and tell each other that stuff in a relationship, we don't need to guess.
If he does it all the time - especially if you both do it - you might benefit from some couples counselling to help you communicate more effectively. If it's just him, he might need an ultimatum.