The distributive law $4\left (x+y \right)=4x+4y $ because $4\left (x+y \right) =\left (x+y \right) +\left (x+y \right) +\left (x+y \right) +\left (x+y \right)$ , but why is $\left (x+y \right) \left (x+y \right) =xx+xy+yx+yy$?


$4\left (x+y \right)=4x+4y $ because $4\left (x+y \right) =\left (x+y \right) +\left (x+y \right) +\left (x+y \right) +\left (x+y \right)$

This works because $4$ is a (positive) integer; but for non-integer factors you can't use the "repeated addition"-argument.

but why is $\left (x+y \right) \left (x+y \right) =xx+xy+yx+yy$?

The distributive law works even if $x$ and/or $y$ are not integers.
Keep one of the factors together in a first step, and apply distributivity twice:
$$\begin{align}
(\color{blue}{x}+\color{red}{y})(x+y) & =\color{blue}{x}(x+y)+\color{red}{y}(x+y) \\ & =\color{blue}{x}x+\color{blue}{x}y+\color{red}{y}x+\color{red}{y}y
\end{align}$$
