Note that if $A$ and $B$ are vectors representing two sides of a triangle, then the third side is represented by vector $C=B-A$. Let the corresponding magnitudes of the sides be $a,b,c$
The cosine rule tells us that $c^2=a^2+b^2-2ab \cos \theta$
Computing the squares of the magnitudes from the components (using Pythagoras) we obtain $$2ab\cos \theta=\sum A_i^2+\sum B_i^2-\sum (B_i-A_i)^2=2\sum A_iB_i$$and the result follows.
Really this is why the scalar product is a useful definition - if it didn't have this geometric aspect we'd be using a different idea. For example, this captures the idea of the component of a force acting in a given direction.
The scalar product has the advantage of expressing the geometric reality without having to specify a basis.