Shingles attacks your nervous system. Avoiding shingles prevents it from damaging your brain, so it isn’t surprising the vaccine reduces dementia.
There are multiple causes for dementia. If I read figure 2 right, the vaccine slightly reduces the chance of mild cognitive impairment, but cuts the chances of dying from dementia by about a third(!)
Also interesting: The vaccine helps at different phases of disease progression.
The simplest explanation is that dementia is due to cumulative damage, not a single event, and that getting shingles is a big hit.
The vaccine probably prevents dementia in the same way staying out of planes makes you invulnerable to parachute failures.