Stability of spectral partitions and the Dirichlet-to-Neumann map