You proved that
$$a_1a_2\cdots a_{2^m} \leq \left(\frac{a_1+a_2+\cdots +a_{2^m}}{2^m}\right)^{2^m}\qquad\forall m\in \Bbb N, \tag{$\star\star$}$$
and you want to prove
$$a_1a_2\cdots a_n\leq\left(\frac{a_1+\cdots + a_n}{n}\right)^n\qquad\forall n\in\Bbb N\tag{$\star$}.$$
You have stablished $(\star)$ for $n=2$ so you have to prove it now for all $n\gt 2$. So pick $n\gt 2$ and $n$ numbers $a_1,\ldots,a_n$.
Now, you can use $(\star\star)$ for a list of numbers of size a power of two. You don't know if $n$ is a power of 2 but you know that sure there is a $m$ so that $2^m\gt n$, so let's add some numbers to our list so we end with a list of size $2^m$.
Which numbers should we add? We don't know, but the most simple thing we can do is add the same number several times (after all we're trying, we don't know if it will work), then our list will be $a_1,\ldots,a_n,\underbrace{x,\ldots,x}_{2^m-n}$.
Using $(\star\star)$ we get
$$a_1\cdots a_n\cdot x^{2^m-n}\leq \left(\frac{a_1+\cdots+(2^m-n)x}{2^m}\right)^{2^m}.\tag{$\ast$}$$
Now you wonder, it would be nice if $x$ had the ability of turn$\frac{a_1+\cdots+a_n+(2^m-n)x}{2^m}$ into $\frac{a_1+\cdots+a_n}{n}$,is there such $x$? That question is answered by the equation
$$\frac{a_1+\cdots+a_n+(2^m-n)x}{2^m}=\frac{a_1+\cdots+a_n}{n},$$
which by solving for $x$ tells you that
$$x=\frac{a_1+\cdots+a_n}{n}$$ work.
And it turns out that this $x$ does the magic to turn $(\ast)$ into $(\star\star)$. I don't know if Cauchy got it this way, but it's a possible path.