[Abridged] Filaments and hubs have received special attention recently thanks to studies showing their role in star formation. While the column density and velocity structures of both filaments and hubs have been studied, their magnetic fields (B-field) are not yet characterized. We aim to understand the role of the B-field in the dynamical evolution of the NGC 6334 hub-filament network. We present new observations of the dust polarized emission at 850$mu$m towards NGC 6334 obtained with the JCMT/POL-2. We study the distribution and dispersion of the polarized intensity ($PI$), the polarization fraction ($PF$), and the B-field angle ($theta_{B}$). We derive the power spectrum of the intensity and $theta_{B}$ along the ridge crest. Our analyses show a complex B-field structure when observed over the whole region ($sim10$ pc), however, at smaller scales ($sim1$ pc), $theta_{B}$ varies coherently along the filaments. The observed power spectrum of $theta_{B}$ can be well represented with a power law function with a slope $-1.33pm0.23$, which is $sim20%$ shallower than that of $I$. This result is compatible with the properties of simulated filaments and may indicate the processes at play in the formation of filaments. $theta_{B}$ rotates from being mostly perpendicular to the filament crests to mostly parallel as they merge with the hubs. This variation of $theta_{B}$ may be tracing local velocity flows of matter in-falling onto the hubs. Our analysis suggests a variation of the energy balance along the crests of these filaments, from magnetically critical/supercritical at their far ends to magnetically subcritical near the hubs. We detect an increase of $PF$ towards the high-column density star cluster-forming hubs that may result from the increase of grain alignment efficiency due to stellar radiation from the newborn stars.