Ultrafast switching of topological invariants by light-driven interlayer vibrations