Good question! There are several answers. First the cages have serrated edges that look like little teeth to grip into the bone. As the fusion takes place, bone grows in and around the implant, locking it in place.
Second if the surgeon doesn’t remove it, there’s a strong ligament along the back side of the spine called the posterior longitudinal ligament or PLL. If the implant did slip back, it would be stopped by the PLL.
Sometimes with the anterior cages the surgeon also puts in some screws from the back. This adds an extra degree of stability. The fusion is strong enough to hold the bones from moving. Without movement the implant is even less likely to shift.
And finally, the disc is made up of two parts. There’s the tougher outer covering called the annulus and the softer, inner center called the nucleus pulposus. When the surgeon removes the disc, the back half of the annulus outer covering is left intact. The cage is inserted until it comes up against the posterior annulus, which keeps it from going any further back.