If there were an absolutely logical, mathematical derivation, then this wouldn't be physics. Ultimately, one has to simply postulate something and treat it as a working hypothesis to be verified by experiment.
First we assume the equivalence principle, which tells us how matter is affected by curved spacetime. This is essentially the same thing as the basic postulate of Riemannian geometry: in the limit as displacements become small, spacetime looks flat and inertial observers travel in straight lines. For motions that are no longer infinitesimal, these "straight lines" extrapolate to geodesics.
Next one needs the other piece of the puzzle: how is spacetime affected by matter? We assume that some sort of matter-energy density must be the source of curvature. We know that matter-energy satisfies a local conservation law (due to the equivalence principle), so we choose the simplest object constructed out of matter-energy that obeys such a conservation law in relativistic mechanics: the stress-energy tensor. This object has two indices, is symmetric, and has zero divergence. To couple it to curvature, we need to form some object out of the curvature tensor that also has two indices, is symmetric, and has zero divergence. The simplest such object is the combination R_{\mu\nu} - \frac12 R g_{\mu\nu} + \Lambda g_{\mu\nu}. So, we set this object proportional to the stress-energy tensor, and work out the constant of proportionality by looking at the weak-field limit.
The weak-field limit gives an additional constraint: the theory must reduce to Newtonian gravity for weak fields. Historically, these steps were worked backwards, starting from the weak field limit and then guessing what kinds of metric theories might produce it. There were competing theories besides Einstein's (notably Nordstrom's) that predicted different phenomena, either slight variations or drastic ones (Nordstrom's predicts no bending of light by gravity, for example).