Injectivity is because $X$ is separated. The locus where two morphisms $S \to X$ agree is a closed subscheme and if it contains the generic point, it's everything.
For surjectivity, we can "spread out" the morphism $Spec K \to X$ to a morphism $U \to X$ from an open subset $U \subset S$ and then use the valuative criterion to fill in the finitely many missing point.