Update and note: In the answer below, I do assume the OP and reader are aware of the Galilean relativity of motion but wonder why the invariance of the speed of light cannot be used to find an absolute rest frame.
If this isn't he case, then Rod Vance's excellent answer is more appropriate.
I switch on the torch and measure the amount of time it takes for the
light to reach the photosensor.
With what apparatus?
Evidently, you have a clock, at one end of the coach, that records the time that the torch is activated. Call this time $t_1$.
Then, you have a clock at the other end of the coach that records the time that the light reaches the photo sensor. Call this time $t'_2$. The prime indicates here that this value is from a different clock.
So, to calculate the transit time, you take the difference in the readings of two, spatially separated clocks:
$$\Delta t = t'_2 - t_1$$
Your calculation assumes that both clocks are synchronized, according to some convention, such that the difference in the reading of the clocks is meaningful.
But how do you know the two spatially separated clocks are synchronized?
According to Einstein synchronization, one synchronizes spatially separated clocks with light signals which guarantees that one will measure the one-way speed of light to be $c$.
Put another way, before you perform you experiment, you must verify that the clocks are synchronized. What does this mean? For Einstein synchronization, we have:
According to Albert Einstein's prescription from 1905, a light signal
is sent at time $\tau_1$ from clock 1 to clock 2 and immediately back,
e.g. by means of a mirror. Its arrival time back at clock 1 is $\tau_2$.
This synchronisation convention sets clock 2 so that the time $\tau_3$
of signal reflection is defined to be $\tau_3 = \tau_1 +
> \tfrac{1}{2}(\tau_2 - \tau_1) = \tfrac{1}{2}(\tau_1 + \tau_2)$
When your clocks are synchronized in this way, the outcome of your experiment is guaranteed to be $\Delta t = \frac{L}{c}$, i.e., your result will be independent of the speed of the train relative to the tracks (or anything else).
Essentially, this is how the invariance of $c$ is made consistent with the relativity of motion. The Lorentz transformation assumes this synchronization convention in order to produce this result.
See the Wikipedia article "One-way speed of light" for more details.
The bottom line is that one cannot assume that elapsed time, as measured by two spatially separated clocks is independent of a synchronization convention.
Only elapsed times, as measured by one clock, e.g., a two-way speed of light measurement, are invariant (absolute).