Hi Practice,
Sorry you are going through such stress and upset. The "how" of how this can happen can be very baffling indeed. Dementia effects the brain in many mysterious ways. It doesn't follow one singular and straight path.
What you describe, however, is not that unusual. People who have Dementia can have very shaky moments and later in the day find some stability. Some states of mind are transient and will come and go.
I am sure others will be along with a better description and maybe even some helpful links to videos and such. I know I've found much comfort in just better understanding how Dementia can work.
As for when he doesn't recognize you. This is always one of the most upsetting and shocking times in a loved-one's life. Both for you and for them. I think you will find that it generally is not helpful to argue with the person suffering from Dementia. Since things seem VERY real to them, it can only upset and agitate them further to have someone trying to punch holes in their very real "reality".
Others will come along soon to tell you what they have done in your situation. In ours, we don't question. Dad, just last week, was very upset because he KNEW there was a news crew coming to his room at the care home and he just wasn't up to being filmed. We told him it would be OK and we would go speak to them straight-away to ensure they didn't bother him.
Wishing you peace,