Postherpetic neuralgia (PHN) is a neuropathic pain syndrome characterized by persistent burning or stinging pain, and its underlying pathogenesis is still unclear. Although conventional resting-state magnetic resonance imaging (rs-fMRI) studies have revealed abnormal resting-state functional connectivity (rsFC) in PHN patients, dynamic functional connectivity (dFC) remains unexplored. In this paper, a sliding time window method was used to generate a dFC matrix, and rs-fMRI data from 55 PHN patients, 55 Herpes Zoster (HZ) patients, and 50 healthy controls (HCs) were analyzed. Machine learning was used to determine whether these abnormal dFC values could be used as neuroimaging markers of the transition from HZ to PHN. All dFC matrices were clustered into two reoccurring states, and the state transition metrics were obtained. We found that patients with PHN were in State 1, which is characterized by weak connections between the networks, more often than patients with HZ (p < 0.05). We also found that in State 1, compared with that in HCs, the dFC between the BGN and SN in HZ patients increased. In State 2, the dFC of PHN patients was lower than that of HZ patients and HCs, and the dFC was mainly observed in the DMN, SN, DAN, VN and LN. The results of the SVM classifier revealed that the change in dFC between the BGN and DMN may be a strong neuroimaging marker of the transition from HZ to PHN. These findings further our understanding of the neuropathological mechanism of PHN.