Thanks for all the replies, let me see if I can make sense of it all....
So yes, as I expected, the diagram I showed does not really achieve anything with the optocoupler.....
If the goal is to use an optocoupler, yes, I could add an additional power supply to the small processor, (such as a 120V AC to 5V USB charger) but my mind suggests to me that in fact everything in my house ultimately has a common ground.. the charger and the power supply for the layout would be connected to the same power supply. (Even with AC, the neutral is bonded to ground at the breaker box.)
My entire layout system; Intellibox, two boosters, signals, s88 modules, track, 12V and 5V DC, circuits all use a common ground, and that ground is also tied to the ground of the house and the PC connected to the Intellibox. This allows all the accessory consumers of current to have a simple wiring system that ties back into a ground bus around the layout. Does it make sense to now introduce a quasi-separate set of power supplies?
Given that the goal is to know when the rail is no longer isolated, if I tied the GND of the ESP8266 to the layout ground, what are the possible bad side effects?
Possible dangers:
- Digital current could find its way to the isolated rail (by a derailment or metal object bridging the center rail to the isolated rail), and only to that rail and not to ground, allowing a large current to run into ESP8288 digital pin and let the smoke out.
- Noise?
- Static discharge?
Is the solution perhaps to simply prevent those dangers from being realised?
Clearly I could add a diode to the circuit between the rail and the ESP8266 pin to prevent current running into the ESP8266.
I could also add a resistor to that circuit, (the 3.3V pins I will be using have pull-up resistors already but not sure if that is the same thing)
The pins can sink to 0V or supply 3.3 V with a maximum current of just 12mA.
Something like this:

(I added orange digital center rail signal - most likely source of stray current)
Does that sort out the danger of stray current?
For noise, what sort of capacitor is suggested and where? (I struggle to understand electrical filtering.)
I do expect some detection tracks to be bridged for extended periods of time. When a train stops on one, it will be bridged continuously.
I also expect many of these to be bridged simultaneously.
Per, If there is a voltage drop, current must be flowing, no?
You lost me completely on all the diodes stuff... I understand what anti-parallel is, but don't understand what you are suggesting.
I am also perfectly happy to have the sensors normally 'high' and go low when activated. I can flip the logic trivially in the software.