I have this integral:
$$ \int{e^{x} \sin{\left (a - x \right )} d x}\tag{1} $$
After two consecutive integration by parts I arrived to the original integral:
$$ \int{e^{x} \sin{\left (a - x \right )} d x} = e^{x} \sin{\left (a - x \right )} + e^{x} \cos{\left (a - x \right )} - \int{e^{x} \sin{\left (a - x \right )} d x}\tag{2} $$
I know that when you arrive to the original integral you can solve it in the following way.
In (2) add the original integral (1) in both sides. You get to:
$$ 2\int{e^{x} \sin{\left (a - x \right )} d x} = e^{x} \sin{\left (a - x \right )} + e^{x} \cos{\left (a - x \right )}\tag{3} $$
Divide by two in both sides, and add the constant $C$ on right-hand side:
$$ \int{e^{x} \sin{\left (a - x \right )} d x} = \frac{e^{x} \sin{\left (a - x \right )} + e^{x} \cos{\left (a - x \right )}}{2}+C\tag{4} $$
My questions are: Why does this happen? That you arrive to the same integral that you were integrating. In the case of exponents you get something bigger ($\int{u^ndu} = \dfrac{u^{\bf{n+1}}}{n+1}+C$), but in this case I arrived to the very same function. Is it related to sine being a periodic function?
And, I solved it using integration by parts. Why is it valid to solve for the original integral?
One thing that is very different about the derivatives of $\sin u$ and $u^n$ is that when we repeatedly differentiate $u^n$ we get $\frac{d}{du} u^n = u^{n-1}$, $\frac{d^2}{du^2} u^n = u^{n-2}$, $\frac{d^3}{du^3} u^n = u^{n-3}$, etc., and we never "get back" to $u^n$, but the second derivative of $\sin u$ with respect to $u$ is $$ \frac{d^2}{du^2} \sin u = -\sin u. $$ That is, by differentiating twice, you get back the original function but with a sign change.
It's not merely that the sine function is periodic, but that it is the same shape as its own derivative, just a little out of phase: $$ \frac{d}{du} \sin u = \cos u = \sin\left(u +\frac\pi4\right). $$
As for why your method of solving the integral is valid: if an equation is true then it's true, and so is anything else that you can derive by valid reasoning from the equation. Notice that "getting back the same function" doesn't always get you the kind of answer you want; for example, if you apply integration by parts twice more to your integral you will get \begin{align} \int e^x \sin(a - x)\, dx &= e^x \sin(a - x) + e^x \cos(a - x) \\ & \qquad - e^x \sin(a - x) + e^x \cos(a - x) + \int e^x \sin(a - x)\, dx. \end{align} This also is a true equation, but when you try to "collect" the integrals on the left-hand side this equation tells you nothing more than the obvious fact that $$ e^x \sin(a - x) + e^x \cos(a - x) - e^x \sin(a - x) + e^x \cos(a - x) = 0. $$ In fact, the second integration by parts actually doesn't give you back exactly the integral you started with: it gives you minus that integral, which is what makes it possible to solve the integral the way you did.