So, we don't know if this is the case, but one way to do this is not to ask the phones but the cells. The mobile network has to know where the phones are by cell; the cells are often small relative to the speed of the train; there are also cells installed specifically to improve service on trains, or provide a base station to the train wifi, or for communications to railway staff.
If you get a bunch of phones switching cell near simultaneously, you can tell that a train movement across the cell boundary has probably happened. Then correlate that with the other data feed about train blocks, and bob's your uncle.
Only about 50% of trains have wifi: https://www.businesstravelnewseurope.com/Ground-Transport/UK... ; but it's easy to imagine getting the mobile hotspot on the train to share its GPS location as well.
You're missing the fact that the system is also divided into explicit signal blocks and those blocks do report train presence to a centralized system[1]. I am not certain if they want to share that information, but if someone got serious about building a system like signalbox I'd expect that NetworkRail would either offer their data, a degraded version of their data on a lag for security reasons, or consider those security reasons so serious that they'd attempt to prohibit deriving that data from cell signals.
1. Mostly, some signal blocks are still entirely manually managed but, IIRC, at this point those manually managed segments are low traffic areas where only one train is allowed into the block group at a time even if the old signal management systems would allow multiple trains.