Einstein assumed in the derivation of his field equations that the covariant derivative (defined through the metric) of the energy momentum tensor of matter is zero, i.e. $$\nabla_{\mu}T^{\mu\nu}_{\rm matter}=0,$$
no matter how distorted the spacetime is.
It seems such a conclusion cannot be reached at via Nöther's theorem (since the metric is itself changing over spacetime). So my question is how did he have this insight then, and how would one justify the correctness of this assumption in retrospect from a Lagrangian point of view now?
If it's based on the existence of infinitesimal coordinate transformations that fix the boundary of some volume in spacetime, then would this also imply that the energy momentum tensor of any field will always have zero covariant derivative with or without gravity?
Edit: Previous form of the question had an abuse of language, viz., that I referred to the "vanishing of the covariant derivative of the energy-momentum tensor" as "energy momentum tensor is covariantly conserved". This was rightly pointed out by Ben Crowell in his answer and, I've edited the question and made it mathematically precise for the sake of clarity.