Why is integral of $(x+y)^2 \,dx$ different than integral of $(x^2+ 2xy + y^2) \,dx$? I calculated the integral of $(x + y)^2 \,dx$ using the substitution method and got $\frac{1}{3}(x+y)^3$ as result.
Then I applied the distributive property to $(x + y)^2$, calculated the integral of $(x^2+2xy+y^2) \,dx$ and I got $\frac{x^3}{3}+x^2y+xy^2$ as result, which is not equal to $\frac{1}{3}(x+y)^3$.
But, knowing that $(x+y)^2$ = $x^2+2xy+y^2$, why aren't the results of these integrals the same?

Their difference is constant (it's $\frac{y^3}3$). So, you got the same answer by both methods.
To be more precise,$$\frac13(x+y)^3=\left(\frac13x^3+x^2y+xy^2\right)+\frac{y^3}3,$$and therefore\begin{align}\frac{\mathrm d}{\mathrm dx}\left(\frac13(x+y)^2\right)&=\frac{\mathrm d}{\mathrm dx}\left(\left(\frac13x^3+x^2y+xy^2\right)+\frac{y^3}3\right)\\&=\frac{\mathrm d}{\mathrm dx}\left(\frac13x^3+x^2y+xy^2\right).\end{align}
