There are quite a few reasons and it can be quite complicated but i'll try and give an overview!
For mobile reception;
- Most glass used on trains has a metal 'film' of sorts which reduces glare/heat gain inside the carriage, however this reduces the strength of the signal that passes through.
- Tunnels, embankments, cuttings. If you don't have line of sight to the mast, the signal needs to diffract (bend) around the obsticable or go through it. This can be rather difficult! In some dense urban environments, mid/high-rises adjacent to the track may cause a similar effect.
- Available sites. There may not always be a good site to place a mast near the railway, so you can be on the very edge of the area it covers.
- Deployment of low-frequency spectrum. The lower the frequency, the further it can travel and the better it can penetrate obstructions. Most operators hold an amount of spectrum in the 800-900MHz range, but some have more than others, and some restrict what phones can access it (for compatibility reasons!). If you happen to be on an operator that has only a little amount, or a phone that isn't allowed to access it then you'll get poor performance if you have any signal at all. More low frequency spectrum will be auctioned off in the next few years once it has been vacated by Digital TV.
Many of the operators do consider railway coverage an important metric these days, and you'll often see planning applications that use signal strength data collected from onboard a train to back up the planning application. However, planning can be a significant challenge - NIMBYism and misguided phobia of masts is unfortunately more common than ever.
There has also been discussion of sharing Network Rail's GSM-R masts - which are perfectly placed for track coverage. However, there is some concern over interference with what is a safety critical system - so understandably this something that's quite slow moving.
For WiFi;
- Unless there's some sort of fault, the actual WiFi signal strength you receive should be quite strong - most of the time the access point is inside the carriage.
- From the access point in the carriage though, it still has to get somewhere. The WiFi system uses the mobile network as a backhaul, and so it suffers from some of the same problems as above. However;
- The antennas are large and roof mounted, avoiding the signal loss due to the glass and are generally able to pick up a stronger signal than your phone would even if it was on top of the carriage.
- The mobile technology used is often more advanced than what most consumer phones would use, for example allowing it to aggregate multiple frequencies from a single operator for additional bandwidth.
- Multiple radios are themselves aggregated, across multiple operators. So if an area only had good coverage from a signal operator, there would still be some usable bandwidth available. However, if there were multiple operators then their capacity could be aggregated further.
- Even with all of the techniques above to make the train-to-mast bandwidth as fast as possible, you're now sharing that among several hundred people.
- To provide a fair service to all users, a per-device speed restriction will often be imposed. With most operators, you'll get a set amount of 'high speed' data (commonly around 50 to 200MB of data at 1-3Mbps), after which you'll get unlimited 'slow' data (commonly 0.25 to 0.5Mbps). The 'slow' rate is still usable for messaging and Twitter, but webpages will definitely be noticeably slower.
Hopefully that makes some level of sense! I can try and elaborate on any points if you want more detail!