Topological phase transition in the quench dynamics of a one-dimensional Fermi gas