How did Einstein relate energy and the curvature of spacetime?
Ultimately the justification for Einstein's equation was experimental.
The assumption that the equivalence principle holds strongly suggests that gravity has to be described by a metric theory, that is the theory relates the curvature of spacetime to some property of the matter and energy present. The first such theory was Nordström's theory of gravity proposed in 1913, in which the field equation is simply:
$$ R = 24\pi T $$
where $R$ is the Ricci scalar and $T$ is the trace of the stress-energy tensor. This is a perfectly good theory of gravity with all the features we expect. It respects the equivalence principle and is derivable from an action principle. But it was unable to account for the perihelion shift of Mercury and predicted that gravitational lensing did not occur, while Einstein's equation:
$$ R_{\mu\nu} - \frac{1}{2} R\,g_{\mu\nu} = 8 \pi T_{\mu\nu} $$
does correctly describe Mercury's orbit and gravitational lensing.
Einstein's equation is not the unique theory relating curvature and mass/energy but it is the simplest one that works. That's why Einstein chose it.