Itô's formula states that
$$f(t,W_t)-f(0,W_0) = \int_0^t \partial_x f(s,W_s) \, dW_s + \int_0^t \left( \frac{1}{2} \partial_x^2 f(s,W_s) + \frac{\partial}{\partial s} f(s,W_s) \right) \, ds \tag{1}$$
for any (nice) function $f$. Equivalently,
$$\int_0^t \partial_x f(s,W_s) \, dW_s = f(t,W_t)- f(0,W_0) - \int_0^t \left( \frac{1}{2} \partial_x^2 f(s,W_s) + \frac{\partial}{\partial s} f(s,W_s) \right) \, ds. \tag{2}$$
Now let's consider the stochastic integral $\int_0^t s \, dW_s$. If we can find a function $f$ such that
$$\partial_x f(s,x) = s \tag{3}$$
then the left-hand side of $(2)$ is nothing but $\int_0^t s \, dW_s$, i.e. exactly the stochastic integral which we are looking for. Integrating the equation $(3)$ with respect to $x$ yields
$$f(s,x) = sx + c$$
for some constant $c$; let's choose $c:=0$. Then $$\partial_x^2 f(s,x) = 0 \qquad \partial_s f(s,x) = x,$$ and therefore (2) gives $$\int_0^t s \, dW_s = t W_t - \int_0^t W_s \, ds.$$
See e.g. this question and this question for further examples.