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?

The meaning of the word "constant" gets too little attention in our pedagogy. "Constant" means not changing as something else changes, but what is the thing in the role of "something else"?
\begin{align}
& \int (x^2 + 2xy+y^2)\, dx \\[10pt]
= {} & \frac{x^3}3 + x^2 y + xy^2 + \text{constant} \\[10pt]
= {} & \frac 1 3 \left( x^3 + 3x^2y +3xy^3 \right) + \text{constant} \tag 1 \\[10pt]
= {} & \frac 1 3 \left( x^2 + 3x^2y + 3xy^2 \right) + \Big( \tfrac 1 3 y^3 + \text{constant} \Big) \tag 2 \\
& \text{In this context, “constant” means not depending} \\
& \text{on $x,$ i.e. not changing as $x$ changes, because $x$ is} \\
& \text{the variable with respect to which we are integrating.} \\
& \text{The function whose antiderivative we seek is a} \\
& \text{function of $x$ with $y$ held constant. The “constant”} \\
& \text{In line $(2)$ is the “constant” in line $(1)$ minus $\tfrac13y^3.$} \\
& \text{Get used to that. And $\tfrac 13y^3$ is “constant” since it} \\
& \text{doesn't change as $x$ changes.} \\[10pt]
= {} & \frac 1 3 (x^2 + 3x^2y+3xy^2 + y^3) + \text{constant} \\[10pt]
= {} & \frac 1 3 (x+y)^3 + \text{constant.}
\end{align}
Appendix: Whoever hesitates to think the meaning of “constant” deserves somewhat more attention in the classroom than it usually gets should consider this:
\begin{align}
& \frac d {dx} 2^x = \lim_{h\,\to\,0} \frac{2^{x+h} - 2^x} h \\[10pt]
= {} & \lim_{h\,\to\,0} \left( 2^x \cdot\frac{2^h-1} h \right) & & (\text{just algebra}) \\[10pt]
= {} & 2^x \lim_{h\,\to\,0} \frac{2^h-1} h \\
& \text{because $2^x$ is constant} \\
& \text{and “constant” means} \\
& \text{not depending on $h$} \\[10pt]
= {} & \big( 2^x\cdot\text{constant} \big) \\
& \text{and “constant” means} \\
& \text{not depending on $x.$}
\end{align}
