First of all without loss of generality we can order $n_i$ so that

\begin{equation} n_1 \leq n_2 \leq \dots \leq n_r \end{equation}

Now we try to construct a prefix code in increasing order, i.e., $i = 1, 2, \dots r$. There exists a prefix code if and only if at each step $j$, there is at least one codeword to choose that does not contain any of the previous $j - 1$ codewords as a prefix. In other words, the codeword $\sigma_j$ must not contain any of the previous codewords $(\sigma_1, \sigma_2, \dots \sigma_{j-1})$ as a prefix. For $\sigma_j$, there are $s^{n_j}$ combination of codewords we could choose from if there was no prefix constraints. But due to the codeword at a prior step $k < j$, $s^{n_j - n_k}$ codewords are now forbidden because they contain $\sigma_k$ as a prefix. Furthermore, the sets of forbidden codewords due to different prior steps are exclusive. Since if any two prior steps forbid the same codeword at step $j$, that would imply the smaller of the codewords in the two prior steps is a prefix of the other one, which contradicts the prefix assumption.

Therefore we know the total number of forbidden codewords at step $j$ is

\begin{equation} \sum_{i=1}^{j-1} s^{n_j - n_i} \end{equation}

There exists a prefix code if and only if we have a codeword to choose at every step, namely,

\begin{equation} s^{n_j} > \sum_{i=1}^{j-1} s^{n_j - n_i}, \forall j = 2, 3, \dots r \end{equation}

Since every term above is an integer, this is equivalent to

\begin{equation} s^{n_j} \geq \sum_{i=1}^{j-1} s^{n_j - n_i} + 1 = \sum_{i=1}^{j} s^{n_j - n_i}, \forall j = 1, 2, \dots r \end{equation}

Now divide by $s^{n_j}$ on both sides we get

\begin{equation} 1 \geq \sum_{i=1}^{j} s^{- n_i}, \forall j = 1, 2, \dots r \end{equation}

Now since every term above is non-negative, this is equivalent to Kraft's inequality

\begin{equation} \sum_{i=1}^{r} s^{- n_i} \leq 1 \end{equation}

Notice that every argument in the proof goes both ways. Thus this proves that Kraft's inequality is both a necessary and sufficient condition for the existance of a prefix code.