How does $\sin(\frac{\pi}{2}+h)$ become $\cos h$, and $\cos h-1$ become $-2 \sin^2 (\frac{h}{2})$? I have questions regarding trigonometry used in the solution of this problem:

Discuss the differentiability of $f(x)$ at the point $x=\frac{\pi}{2}$.
$$f(x) = \begin{cases}
1, & x<0 \\[4pt]
1+\sin x, &0\leq x<\frac\pi2 \\[2pt]
2+\left(x-\frac{\pi}{2}\right)^2, &x\geq\frac\pi2
\end{cases}$$

$$\begin{align}
Lf'\left(\frac{\pi}{2}\right)&=\lim_{h\to0^-} \frac{f(\frac{\pi}{2}+h)-f(\frac{\pi}{2})}{h} \\[4pt]
&=\lim_{h\to0^-} \frac{1+\sin(\frac{\pi}{2}+h)-2}{h} \\[4pt]
&=\lim_{h\to0^-} \frac{\cos h-1}{h} \\[4pt]
&=\lim_{h\to0^-} \frac{-2 \sin^2 (\frac{h}{2})}{h} \\[4pt]
&=-\lim_{h\to0^-} \left(\frac{\sin\frac{h}{2}}{\frac{h}{2}}\right)^2\cdot\frac{h}{2} \\[4pt]
&=0
\end{align}$$

The last two line was little bit weird (It was looking just like magic) to me.

*

*How they converted $$\sin(\frac{\pi}{2}+h)=\cos h$$?

*How they wrote $$\cos h-1 = -2 \sin^2 (\frac{h}{2})$$
I think I am missing something on trigonometry.

Both of your questions are answered by formulas which can be derived from the angle sum formulas for sine and cosine given by
\begin{align}
\sin(\alpha \pm \beta) &= \sin \alpha \cos \beta \pm \cos \alpha \sin \beta \\
\cos(\alpha \pm \beta) &= \cos \alpha \cos \beta \mp \sin \alpha \sin \beta
\end{align}

For the first part, using the angle sum formula for sine we get
$$
\sin\left(\frac{\pi}{2}+h\right) = \underbrace{\sin\left(\frac{\pi}{2}\right)}_{\color{blue}{1}}\cos(h) + \sin(h) \underbrace{\cos\left(\frac{\pi}{2}\right)}_{\color{blue}{0}} = \cos(h)
$$
For the second part, you can use the double angle formula for cosine (which is just the angle sum formula when $\alpha = \beta$) to obtain said relationship:
\begin{align*}
&\cos(2u) = \underbrace{\cos^2(u)}_{\color{blue}{1 - \sin^2(u)}} - \sin^2(u) = 1-2\sin^2(u)  \\
\implies& -2\sin^2(u) =\cos(2u) - 1\overset{\color{purple}{u = h/2}}{\implies}-2\sin^2\left(\frac{h}{2}\right) =\cos(h) - 1
\end{align*}
