Because they are left unmolested for long periods of time. We can see this by looking at entries between wars in the Tale of Years (LotR appendix B).
For example, the beginning of the second age follows the War of Wrath, in which Morgoth's forces were destroyed. At this point, many elves have left Middle-Earth and the Edain are living peacefully on the island of Numenor. According to the Tale of Years, Sauron starts the building of Barad-dur around SA1000, but the war of the Elves and Sauron doesn't start until SA1693. There is nothing to indicate that anyone tried to disrupt the build-up of his forces. Six years later, Sauron defeats the Elves, but then the Numenoreans intervene. The entries for SA1700 and 1701 just say that Sauron is defeated and driven out of Eriador, but the History of Galadriel and Celeborn in the Unfinished Tales spells out the magnitude of the defeat:
In the Battle of the Gwathlo Sauron was routed utterly and he himself
only narrowly escaped. His small remaining force was assailed in the
east of Calenardhon, and he with no more than a bodyguard fled to the
region afterwards called Dagorlad (Battle Plain) ... The army that was
besieging Imladris was caught between Elrond and Gil-Galad, and
Thus the whole of Sauron's invading army is wiped out, but there is no record of any subsequent major fighting until the time of the Last Alliance with war starting in SA3429, more than 700 years after the Battle of the Gwathlo.
There is a similar pattern in the Third Age. According to the Tale of Years, the Nazgul reoccupy Mordor in TA1980 and seize Minas Ithil in TA2000. Between that time and the War of the Ring, the orcs of the Misty Mountains take a beating in the War of the Dwarves and Orcs [TA2793-2799] and at the Battle of Five Armies [TA2941], and there is some fighting between Gondor and Rohan on one side and forces of Mordor/Minas Morgul on the other. However (as was often the case), Sauron let the Haradrim, Easterlings and Corsairs do a lot of his dirty work [TA2475, 2510, 2758, 2885, 2901]. There is no record of Gondor making a major attack against Mordor or Minas Morgul during this time, and Sauron had plenty of time to build up a large force of orcs.
Gandalf remarks upon this in The Last Debate:
... he [Sauron] has not built up his power by waiting until his
enemies are secure, as we have done.
That's a bit harsh when applied to Gondor and Rohan, since they lacked the strength to attack Sauron directly. On the other hand, much evil might have been averted if the Numenoreans had acted more agressively after the Battle of the Gwathlo.