Similarly to what MSteen said, for me it happens more when I'm trying to get to sleep. You know when you're trying to sleep but you have a song in your head and it won't go away? It's like that but I'm playing chess in my mind instead.
Often the moves don't make sense and weird things happen, and I don't think I've ever "won" or "lost" a game, it's just like my head is scanning through different positional possibilities.
Usually it's mating sequences rather than full games.
when the men on the chessboard get up and tell you where to go
and youve just had some kind of mushroom and your mind is moving slow
Go ask alice, I think she'll know
When logic and proportion have fallen sloppy dead
And the white knight is talking backwards
And the Red Queen off with her head
Remember what the doormouse said
FEED YOUR Head FEED YOUR Head