We study the nonequilibrium dynamics of the linear-to-zigzag structural phase transition exhibited by an ion chain confined in a trap with periodic boundary conditions. The transition is driven by reducing the transverse confinement at a finite quench rate, which can be accurately controlled. This results in the formation of zigzag domains oriented along different transverse planes. The twists between different domains can be stabilized by the topology of the trap, and under laser cooling the system has a chance to relax to a helical chain with nonzero winding number. Molecular dynamics simulations are used to obtain a large sample of possible trajectories for different quench rates. The scaling of the average winding number with different quench rates is compared to the prediction of the Kibble-Zurek theory, and a good quantitative agreement is found.