Proof that free scalar field is conformally invariant So, under conformal transformations $$x\mapsto x'\\
\phi\mapsto\phi'(x')=\Omega^{(2-D)/2}\phi(x),$$ where $$\eta_{\mu\nu}\frac{\partial x^\mu}{\partial x^{'\alpha}}\frac{\partial x^\nu}{\partial x^{'\beta}}=\Omega^{-2}(x)\eta_{\alpha\beta},$$ the action transforms like
$$S\mapsto\int d^Dx\,\Omega^{D-2}\partial_\mu(\Omega^{(2-D)/2}\phi)\partial^\mu(\Omega^{(2-D)/2}\phi)$$
(A quick way to get to this equations is by instead considering the associated Weyl transformation as described in an answer in Simple conceptual question conformal field theory). It is then obvious that the action is invariant under scale transformations, i.e. when $\Omega$ is constant. However, why is it invariant when $\Omega$ is not constant? What does one do with the terms involving derivatives of $\Omega$?
 A: As mentioned by @ConnorBehan, the result is only true for Weyl factors coming from conformal transformations. Bruno de Souza Leão Torres stressed to me the importance that said conformal transformations are of the flat metric. Indeed, this proof will only show conformal invariance for the theory coupled to the flat metric.
The conformal transformations of the flat metric are well known: they are generated by translations, rotations, dilations, and special conformal transformations. Invariance under the first three can be checked. This answer will focus on invariance under the last. The key for this is noting that every special conformal transformation is a translation conjugated by inversions $I:x^\mu\mapsto x^\mu/x^2$. Thus, if we check the theory is invariant under inversions then it turns out that the theory will be invariant under special conformal transformations.
Inversions have the conformal factor $\Omega=x^{-2}$. Then, we have
$$\partial_\mu(\Omega^{-\frac{D-2}{2}}\phi)=(D-2)(x^{2})^{\frac{D-4}{2}}x_\mu\phi+(x^2)^{\frac{D-2}{2}}\partial_\mu\phi.$$
We now need to compute the square of this vector and multiply by the remaining factor of $\Omega^{D-2}=(x^2)^{2-D}.$ The resulting term quadratic in derivatives is then clearly the original action. The remaining terms are
$$2(D-2)(x^2)^{-1}x^\mu\phi\partial_\mu\phi+(D-2)^2(x^{2})^{-1}\phi^2.$$
On the first term we can use $2\phi\partial_\mu\phi=\partial_\mu(\phi^2)$. Moreover, note that
$$\partial_\mu((x^2)^{-1}x^\mu)=(x^2)^{-1}(D-2).$$
Then these remaining terms are a total derivative
$$(D-2)\partial_\mu((x^2)^{-1}x^\mu\phi^2).$$
As a final remark, as explained by Bruno in Simple conceptual question conformal field theory, one can modify the scalar field theory so that invariance under any Weyl transformation, even those that can't be undone by diffeomorphisms, is achieved.
