You do the same. I do it too. Everyone does it. The difference is you and I do it all in our heads. Some people, particularly the elderly, no longer have that restraint and do it out loud. People talk to themselves all the time.
Its part of the Dementia. In her mind she is talking to someone that is there. My Mom, it was a little girl. She would tell her to stop doing something. The little girl disappeared when I entered the room.
https://www.dementiacarecentral.com/aboutdementia/facts/stages/
Best of luck!