Solution (source code)

= Solution

Because $\cos0=1$, continuity gives a disc $U$ about zero on which $\cos z\ne0$. The function $-\tan z=(\log\cos z)'$ has a holomorphic primitive $G$ on a sufficiently small disc, normalized by $G(0)=0$. Then
$$
\boxed{f(z)=e^{G(z)/2}}
$$
is holomorphic and satisfies $f(0)=1$ and $f(z)^2=\cos z$ on $U$.

\b[No such square root exists throughout $|z|<2$.] The point $z=\pi/2$ lies in that disc and is a <simple zero> of $\cos z$, since $-\sin(\pi/2)=-1$. Every zero of the square of a holomorphic function has even <order of a zero of a holomorphic function>, contradicting this simple zero.