Why is it wrong to solve the limit this way? Consider the following limit：
\begin{align*}
&\lim_{x\to +\infty}\frac{e^x}{\left(1+\frac1x\right)^{x^2}}\\
&=e^{\lim_{x\to +\infty}(x-x^2\ln\left(1+\frac1x\right))}\\
&=e^{\lim_{x\to +\infty}x^2(\frac1x-\ln\left(1+\frac1x\right))}\\
&=e^{\lim_{x\to 0^+ }\frac1{x^2}(x-\ln(1+x))}\\
&=e^{\lim_{x\to 0^+ }\frac{\frac12x^2}{x^2}}\\
&=e^{\frac12}
\end{align*}
The above solution is correct and another solution is following:
\begin{align*}
&\lim_{x\to +\infty}\frac{e^x}{(1+\frac1x)^{x^2}}\\
&=\lim_{x\to +\infty}\frac{e^x}{[(1+\frac1x)^{x}]^x}\\
&=\lim_{x\to +\infty}\frac{e^x}{e^x}\\
&=1
\end{align*}
Why is that wrong? Is that because we didn't take the limit of both the numerator and the denominator?

(I've colored equals signs below as red when the argument is falty. Apologies to the color-blind.)
You've done this:
$$\lim_{x\to\infty} \frac{f(x)}{g(x)^x}\color{red}=\lim_{x\to\infty}\frac{f(x)}{(\lim_{y\to\infty} g(y))^x}$$
If you could do that kind of substitution, you could solve a lot of problems this way:
$$\lim_{x\to \infty}\left(1+\frac1x\right)^x\color{red}=\lim_{x\to\infty}\left(\lim_{y\to\infty} 1+\frac 1y\right)^x=\lim_x 1^x=1.$$

The real question is why you'd think you could let one tiny part of the limit go to infinity first.
One way to see this is wrong is to compute:
$$\lim_{x\to\infty}\frac{g(x)^x}{(\lim_{y\to\infty} g(y))^x}$$
In your technique, this limit is $1.$
If $L=\lim_{y\to\infty} g(y),$ then let $h(x)=g(x)-L.$ $h(x)$ is the "error."
Since $g(x)=L+h(x),$ we can compute the limit:
$$\lim_{x\to\infty} \frac{g(x)^x}{L^x}=\lim\left(\frac{g(x)}{L}\right)^x=\lim\left (1+\frac{h(x)}{L}\right)^x.$$
All we really know is that $h(x)\to 0.$ So, for example, if $h(x)=\frac 1x,$ then the right side of the limit would be $e^{1/L}.$
In your case, you need an estimate for $h(x)=e-(1+1/x)^x.$ I'm not sure how to do that, but I'd bet, from the actual answer, that $h(x)=\frac{e}{2x}+o\left(\frac1x\right).$

Another way to see the error is to take the first approach, but apply the second answer's logic. We'll just take the logarithms. Your second logic is:
$$\lim_{x\to\infty} (x-x^2\log(1+1/x))\color{red}=\lim_{x\to\infty} x-x\left(\lim_{y\to\infty} y\log(1+1/y)\right)=0.$$
since $y\log(1+1/y)\to 1.$
As you can see here, the common factor of $x$ is the problem. It is true that $1-x\log(1+1/x)\to 0,$ but it is not true that $x(1-x\log(1+1/x))\to 0.$
