This theorem was proved by Max Dehn in early 20th century.
Suppose there is some square whose side $s$ is not rational. Pick some $\mathbb{Q}$-homomorphism $h$ such that $h(1) = 0$ and $h(s) = 1$. Define the area $\sigma(R)$ of a rectangle $R$ with sides $a,b$ by $h(a)h(b)$. We show below that if a rectangle $R$ is partitioned into rectangles $R_i$ then $$\sigma(R) = \sum \sigma(R_i).$$ Take $R$ to be the unit square, and $R_i$ the squares into which it is partitioned. If $R_i$ has side $s_i$ then we get $$0 = h(1)^2 = \sigma(R) = \sum \sigma(R_i) = \sum h(s_i)^2 \geq h(s)^2 = 1.$$ This contradiction shows that all sides must be rational.
It remains to show that $\sigma$ is additive. Extend all sides in the partition of $R$ to get a grid $G_j$. From additivity of $h$ we easily get $$\sigma(R) = \sum\sigma(G_j) = \sum\sigma(R_i).$$
Using very similar methods, you can show the following slightly stronger theorem: Suppose that a rectangle is partitioned into squares. Then all edge lengths are rationally related.
Indeed, if the outside rectangle had sides $a,b$ not rationally dependent then we could pick a homomorphism $h$ such that $h(a)=1,h(b)=-1$, and then get that $-1$ is a sum of squares. Wlog, $a,b$ are both rational, and the previous proof completes the argument.