Without the cosmological constant, the Einstein field equation predicts the universe is expanding. Why is that? It is counter-intuitive because generally gravity should pull things closer and shrink the universe.
3 Answers
The Einstein field equations predict that the universe can expand, not that it is expanding. The fact that the universe is expanding was first observationally discovered by Edwin Hubble in 1929. Before this discovery, Einstein had introduced the cosmological constant to keep the universe from collapsing under the influence of gravity. When he heard of Hubble's discovery, he removed the cosmological constant from the equation, as expansion could explain why the universe wasn't collapsing due to gravity. The inflationary universe theory gives us clues on how the expansion first originated/occurred after the big bang.
Let's consider the motion of a ball in the Earth's gravitational field:
if you just let go of the ball it falls down
if you throw the ball up it first rises then falls down
if you throw the ball really hard it rises, escapes the Earth's gravity and flies off never to be seen again
So with the same ball and the same Earth we can get three different types of behaviour. The difference is of course in the initial conditions i.e. the velocity of the ball at $t = 0$. If we know the equation of motion of the ball then we can work out what initial velocity it had.
The FLRW metric is sort of the equation of motion of the universe, but there's a big difference from the equation of motion of the ball because we can't just choose any initial conditions we want. We only get a solution to Einstein's equations for particular initial conditions, and those are the conditions that the universe was expanding at the Big Bang.
Sp the universe had to start off expending. And you're quite correct that the combined effect of all the matter in the universe is to slow that expansion. If the matter density in the universe is high enough then it slows the expansion to a halt and the universe recollapses, sort of like a thrown ball falling back to Earth. This is called a closed universe. If the matter density in the universe is very low then it can't halt the expansion, sort of like the ball escaping the Earth's gravity. This is called an open universe. We think our universe is in between and it's a flat universe.
The point of all this arm waving is that you are quite correct to say:
gravity should pull things closer and shrink the universe
and actually gravity does to that. However the universe was expanding to start with so gravity has to work against the initial expansion.
Expansion of the universe is not related to gravity. Gravity pull things around mass by bending space. But overall space in the universe just keep expand by other reason