First, if \(\mb{u}\) and \(\mb{v}\) are linearly dependent, then \(\mb{v} = \lambda \mb{u}\) with \(\lambda \ne 0\) (since both vectors are non-zero). If \(\lambda \gt 0\) then both vectors point in the same direction, so their angle should be \(\theta = 0\) or \(\cos \theta = 1\text{.}\) But in this case we see
\begin{equation*}
\mb{u} \cdot \mb{v} = \mb{u} \cdot (\lambda \mb{u}) = \lambda \| \mb{u} \|^2 = \| \mb{u} \| \| \lambda \mb{u} \| = \| \mb{u} \| \| \mb{v} \|
\end{equation*}
which verifies the equality. If \(\lambda \lt 0\) then we have that they point in opposite directions and thus \(\theta = \pi\) or \(\cos \theta = -1\text{.}\) Again we observe
\begin{equation*}
\mb{u} \cdot \mb{v} = \mb{u} \cdot (\lambda \mb{u}) = \lambda \| \mb{u} \|^2 = - \| \mb{u} \| \| \lambda \mb{u} \| = \| \mb{u} \| \| \mb{v} \| (-1).
\end{equation*}
So let us assume they are linearly independent. Then the arrow vectors \(\mb{u}, \mb{v}\) and \(\mb{u} - \mb{v}\) make up a triangle. If the angle at \(\mb{u}\) and \(\mb{v}\) is \(\theta\) then the Law of Cosines (a basic generalization of the Pythagorean Theorem) says that
\begin{align*}
\| \mb{u} \|^2 + \| \mb{v} \|^2 - 2 \| \mb{u} \| \| \mb{v} \| \cos (\theta ) \amp = \| \mb{u} - \mb{v} \|^2 , \\
\amp = (\mb{u} - \mb{v} ) \cdot (\mb{u} - \mb{v} ), \\
\amp = \mb{u} \cdot \mb{u} - 2 \mb{u} \cdot \mb{v} + \mb{v} \cdot \mb{v}, \\
\amp = \| \mb{u} \|^2 + \| \mb{v} \|^2 - 2 \mb{u} \cdot \mb{v}.
\end{align*}
Subtracting \(\| \mb{u}\|^2 + \| \mb{v} \|^2\) from both sides and dividing by \(-2\) gives the result.