What exactly happens in the algebraic steps here? $$ \frac{n(n+1)}{2} + (n+1) = (n+1)(\frac{n}{2} + 1) = \frac{(n+1)(n+2)}{2} $$
I don't understand what happens from the first to the second and from the second to the third one.

Note that $$\frac{n(n+1)}{2} = \frac{n}{2}(n+1)$$ so in the original expression, we have the sum of two terms both of which contain a factor of $(n+1)$. Taking this common factor out we obtain
$$\frac{n(n+1)}{2} + (n+1) = \frac{n}{2}(n+1) + 1(n+1) = (n + 1)\left(\frac{n}{2}+1\right)$$
which is the second expression. As for the third, note that we can rewrite the second factor by putting both terms over the same denominator as such
$$\frac{n}{2} + 1 = \frac{n}{2} + \frac{2}{2} = \frac{n+2}{2}$$
which gives
$$(n + 1)\left(\frac{n}{2}+1\right) = (n+1)\left(\frac{n+2}{2}\right) = \frac{(n+1)(n+2)}{2}.$$
