By 1916, Einstein had successfully presented his Field Equations of Gravity i.e. General Relativity (GR). In year 1917, he attempted to apply his GR equations to describe whole Universe. Following is the link to English Translation of Einstein (1917) paper:
Einstein starts by evaluating compatibility of General Relativity with an infinite Universe and he does evaluate by going into technical details. Basically he was trying to set ‘boundary condition’ for a spatially infinite universe.
At the end he admits that he failed in doing so:
From what has now been said it will be seen that I have not succeeded in formulating boundary conditions for spatial infinity.Einstein (1917)
Einstein was more interested in ‘boundary condition’. He failed in determining the boundary condition for spatially infinite universe. But he would ‘successfully’ determine the same for a spatially finite universe.
So how did he ‘derive’ the idea of Finite Universe? Well … he did not derive. He just introduced this idea as a commonsense alternative. Only one extra thing i.e. Cosmological Constant was needed and every problem would be solved. So let’s see how actually the idea of Finite Universe was introduced and what problems were solved through cosmological constant:
Nevertheless, there is still a possible way out, without resigning as suggested under (b). For if it were possible to regard the universe as a continuum which is finite (closed) with respect to its spatial dimensions, we should have no need at all of any such boundary conditions. We shall proceed to show that both the general postulate of relativity and the fact of the small stellar velocities are com- patible with the hypothesis of a spatially finite universe; though certainly, in order to carry through this idea, we need a generalizing modification (i.e. Cosmological Constant) of the field equations of gravitation.Einstein (1917)
“For if it were possible to regard the universe as a continuum which is finite (closed) with respect to its spatial dimensions …” This sentence clearly shows that finite universe idea was not derived from equations. It was annexed to theory as a commonsense alternative where complexities of infinite option remained unsettled.
How boundary condition was determined? “we should have no need at all of any such boundary conditions.” So problem with regards to boundary condition is solved in a spatially finite universe as now such a boundary condition is not even needed.
And … what were the problems whose solution was the ‘cosmological constant’?
The above quoted paragraph shows that there were two problems:
(i) Finite Universe itself and; (ii) Fact of the smaller stellar velocities.
So the problem was associated with the idea of finite universe. If universe is infinite then there was no need of cosmological constant. With finite universe, Einstein feared that it should be collapsed under gravity.
Generally orbiting objects do not collapse under gravity and Einstein was fully aware of this fact. But why do objects orbit? They orbit due to side-way velocity. Einstein knew this fact also as it is clear from following quote out of same paper:
According to the general theory of relativity the metrical character (curvature) of the four-dimensional space-time continuum is defined at every point by the matter at that point and the state of that matter.Einstein (1917)
But Universe even if finite must have been very big. Einstein was thinking that at cosmic scale matter must be at permanent rest. In following quote, he is saying that at cosmic scales, the relative velocities of stars are very small:
The most important fact that we draw from experience as to the distribution of matter is that the relative velocities of the stars are very small as compared with the velocity of light.Einstein (1917)
On the basis of ‘fact’ that relative velocities of stars are very small, he then concludes that at cosmic scales, all matter must be at permanent rest:
There is a system of reference relatively to which matter may be looked upon as being permanently at rest.Einstein (1917)
“Stars are relatively at rest” … and therefore (finite) universe is at “permanent rest” … Einstein reached to this conclusion and need for introducing ‘cosmological constant’ was invoked.
Because in a finite cosmos, only orbit moving stars could prevent gravitational collapse … since stars were at “rest” … there was no orbiting going on … hence an anti-gravity agent “cosmological constant” was needed to prevent gravitational collapse.
We have seen that basic idea of Einstein was that since stars are relatively at rest therefore finite universe must be at permanent rest. In year 1917, Einstein was definitely not aware that finite island universes (galaxies) do exist where not only that stars are not relatively at rest but they are rotating at faster speed than could be (officially) expected for such galaxies.
Thus in a real finite universe, there was no need of cosmological constant. It was needed only for a flawed hypothetical infinite universe which is at permanent rest.