How could the universe be spatially flat on average, if all forms of energy have positive spatial curvature? EDIT: I stated the current understanding wrong, thanks Koschi for the comment.
In the $\Lambda$CDM model, it's said that the vacuum energy pretty much "balances" the baryonic matter, such that the overall curvature of space is flat.
But if you consider the spatial Ricci curvature, both dark energy and baryonic matter have positive curvature!  To see this, just plug the dark energy equation of state, $p = -\rho$, into the Einstein equation, and choose an orthonormal frame:
$R_{\mu\nu} = T_{\mu\nu} - \frac12 T^{\alpha}_{\alpha}g_{\mu\nu} \\ = -\rho\eta_{\mu\nu} - \frac12 (-\rho - 3\rho)\eta_{\mu\nu} \\ = \rho\eta_{\mu\nu}$
with $\eta_{\mu\nu}$ the (-+++) Minkowski metric.  So the spatial curvature is positive.
The difference is that dark energy has negative curvature along timelike directions (hence accelerating expansion), whereas ordinary matter has positive timelike curvature (hence gravity).  But if we're talking about spatial curvature, it's all positive, so how can they cancel each other out?  Wouldn't space have net positive curvature, such that, if it doesn't abruptly end somewhere, it has to be closed into something like a 3-sphere?
The difference in timelike curvature should just determine whether we keep expanding or undergo the big crunch, so that part I get.
Or does the distinction between spacelike and timelike curvature somehow break down on cosmic scales, kind of like space and time get "mixed up" in a black hole?  If so, how?
 A: I think it is worth keeping in mind that the intrinsic spatial curvature is not the same thing as the spatial components of the spacetime Ricci tensor.  Instead, the intrinsic Ricci tensor $\mathcal{R}_{ij}$ and the spacetime Ricci tensor $R_{\mu\nu}$ are related by a somewhat complicated equation involving the extrinsic curvature $K_{ij}$ of the spatial surface and the acceleration $a_i$ of the unit normal:
$$
\mathcal{R}_{ij} = e^\mu_i e^\nu_jR_{\mu\nu} + 2K_i{}^k K_{kj} - K K_{ij} - \mathcal{L}_uK_{ij} + D_i a_j + a_i a_j
$$
where $e^\mu_i$ is a projector onto the tangent directions of the spatial hypersurfaces, and $\mathcal{L}_u$ is the Lie derivative with respect to the unit normal $u^\alpha$. In an FRW spacetime, isotropy requires the acceleration $a_i$ to vanish, but  the extrinsic curvature $K_{ij}$ is nonvanishing; rather, it is proportional to the induced spatial metric (again by isotropy).  Roughly, the extrinsic curvature is the time derivative of the spatial metric, and hence is nonzero due to the time-dependence in the scale factor.  For spatially flat FRW spacetimes, the intrinsic geometry really is flat, so $\mathcal{R}_{ij}=0$.  However, this doesn't require the spatial projections of $R_{\mu\nu}$ to vanish; instead, they just need to cancel against the extrinsic curvature terms in the above equation.  So there is no inconsistency with having the spatial components of $R_{\mu\nu}$ be positive while simultaneously having the intrinsic geometry be flat.
