Not that this explains it, but IIRC, caller ID information is sent (or was, at one time with land lines) "out of band", in a particular data format, that occurs between the first and second rings.
IIRC, it's done using frequencies that either can't be heard (ie, outside the freq response of the phone), or the sound is "switched off" between rings (quite possibly this, since the "ring" voltage is completely different from the "line-in-use" voltage - so this voltage change can be detected and switch the signaling as needed).
At any rate, it's a known thing, and if you understand how it works, it's possible (well, again, was - for land line phones) to build a box that can inject these signals between the rings so the phone being called will display it. Normally, this is done (IIRC) by the CO, but I think if the info is already there, it doesn't override it.
I might be completely wrong, though; it's been a couple of decades since I last read about how it worked; also, I have no idea how it works in cell-phone land, but likely it hasn't changed because "inertia" and having to support older land-line phones...