Trace of stress tensor vanishes $\implies$ Weyl invariant You often see in textbooks the statement that ${T^\mu}_\mu = 0$ implies Weyl invariance or conformal invariance. The proof goes like 
$$\delta S \sim \int \sqrt{g} T^{\mu\nu} \delta g_{\mu\nu} \sim \int \sqrt{g} {T^\mu}_\mu, $$
where I have varied the action with respect to the metric and assumed $\delta g_{\mu\nu} \propto g_{\mu\nu}$ (i.e. a Weyl transformation).
This does not seem to be completely general because I can imagine a Lagrangian containing matter fields with non-trivial conformal weights. Then the full variation under Weyl tranformation contains a term proprotional to the matter equation of motion.
So I would conclude that the correct statement is more like
$${T^\mu}_\mu = 0, \quad \& \quad \frac{\delta S}{\delta \phi}  = 0\implies \textrm{Weyl invariant}$$
Is it true that Weyl invariance only holds when the matter fields are on-shell or am I missing something?
 A: This answer comes close. Given a specific definition of "conformal transformation," this answer shows that tracelessness of the stress tensor implies conformal invariance of the action without using any equations of motion. This answer is not complete, though, for two reasons. First, the conformal transformation (equation (7) below) does not account for possible "scaling dimensions" of the fields. Second, it doesn't comment on the relationship between the "Weyl invariance" and "conformal invariance" language. I don't know how to address either of these without guessing. This answer considers only conformal transformations, by which I mean a transformation of the dynamic fields whose form is motivated by how a conformal coordinate transformation would affect those fields. This definition will be repeated below where it is used.
Consider the action 
$$
S = \int d^Dx\ \big(\text{integrand}\big)
\tag{1}
$$ 
where the integrand involves a dynamic scalar field $\phi(x)$ and a prescribed background metric $g_{ab}(x)$. The dynamic scalar field $\phi$ is a classical field, not a quantum field. Under arbitrary variations of $\phi$ and $g_{ab}$, the effect on the action is
$$
  \delta S = \delta_\phi S + \delta_g S,
\tag{2}
$$
where $\delta_\phi S$ is the part due to $\delta\phi$, and $\delta_g S$ is the part due to $\delta g_{ab}$. We're thinking of the metric as a prescribed background, not as a dynamic entity, but we can still ask how the action is affected when we vary it. The tensor $T^{ab}$ is defined by 
$$
   \delta_g S \propto \int \sqrt{g}\, T^{ab}\delta g_{ab}.
\tag{3}
$$
The key to this answer is to consider carefully what the definition (3) involves. When we talk about conformal invariance, we're implicitly assuming a prescribed background metric with respect to which "conformal" is defined. To use (3), we temporarily generalize the action to an arbitrary metric, then apply the definition (3), and then set the metric equal to the desired background metric — such as the flat metric. The temporary generalization to an arbitrary metric is not unique, and therefore neither is $T^{ab}$ (they're not all traceless), but that's beside the point here. The point is to show that if the generalization is chosen so that $T^{ab}$ is traceless, then the fixed-metric action is invariant under conformal transformations of the fields $\phi$ alone.
When we generalize $S$ to an arbitrary metric, whichever generalization we use, it us understood that the generalization is chosen so that $S$ would be invariant under diffeomorphisms (defined below) if the metric $g_{ab}$ were one of the dynamic fields. In other words, it is understood that we are temporarily promoting the action to be a general relativistic action, even including an Einstein-Hilbert term if we want to (but that won't affect any of the conclusions if the fixed metric is flat). 
By "diffeomorphism" here, I mean any transformation of the fields+metric ($\phi$ and $g_{ab}$) that agrees with the effect of any coordinate transformation, with the understanding that they are tensor fields so that the coordinate transformation is pulled back / pushed forward to them in the usual way. The important thing here is that we think of this as a transformation of the fields+metric, not a transformation of the coordinates, because the action $S$ is not a function of coordinates. (The coordinates are just dummy integration variables.) In other words, it's important that we only transform the integrand of (1), not the measure $d^Dx$. These are the "diffeomorphisms" under which the temporarily-generalized $S$ should be invariant, as in general relativity.
Generalizing $S$ in this way is a prerequisite for using (3) to define $T^{ab}$. A by-product of generalizing $S$ in this way is that it satisfies
$$
   \delta S=0
\tag{4}
$$
for an arbitrary infinitesimal diffeomorphism $(\delta\phi,\,\delta g_{ab})$. No equations of motion are needed here; the action is constructed to be identically invariant under such transformations. Equations (2)-(4) imply
$$
 \delta_\phi S = - \delta_g S \propto \int \sqrt{g}\, T^{ab}\delta g_{ab}.
\tag{5}
$$
Now, specialize the metric to the desired fixed metric, and specialize the variation $(\delta\phi,\,\delta g_{ab})$ to be a conformal transformation, which (by definition) is a diffeomorphism for which 
$$
\delta g_{ab}(x)=\epsilon(x) g_{ab}(x)
\tag{6}
$$
for some $\epsilon(x)$. The corresponding transformation of the dynamic field $\phi$ is
$$
\delta\phi(x)=\epsilon^a(x)\partial_a\phi(x),
\tag{7}
$$
where $\epsilon^a(x)$ is related to $\epsilon(x)$ in a particular way. Using (6) in (5) and assuming $T^a_a=0$ gives the desired result $\delta_\phi S=0$, which says that $S$ is conformally invariant. The equations of motion are not needed for this.
A: In hindsight, I believe the proofs are correct, but perhaps not stated in the most logical way. If $T^\mu _\mu =0$, you can define all fields of the theory to have vanishing conformal weight. Then, as the two-liner proofs show, such theories are Weyl-invariant.
