A combination of linear algebra and geometry can be useful. If $R$ is a rotation matrix, it satisfies $R^TR=I_n$, where $I_n$ is the $n\times n$ identity matrix. Assume $v,w$ are unit vectors. We compute
$Rv\cdot Rw=(Rv)^T(Rw)=v^T(R^TR)w=v^TI_nw=v^Tw=v\cdot w$
using matrix transpose properties. Thus the dot product is rotation-invariant. Rotations act transitively, which for our purposes means that given $v,w$ we can find a rotation $R$ so that $Rv=e_1$ is the first basis unit vector. After that we rotate around the $x$-axis so that $Rw$ becomes a vector on the $xy$-plane (while $Rv=e_1$ remains unchanged), and we are reduced to the case of $\Bbb R^2$. Here,
$(1,0)\cdot(\cos\theta,\sin\theta)=\cos\theta,$
as desired (where $\theta$ is the angle between the second vector and the $x$-axis, or equivalently $e_1$).