There are an awful lot of ill-informed comments on here, and a minority who try to argue with Railways staff, such as SWT Driver, that sticking your head out of the window is not dangerous.
A number of us professional Railwaymen on here will have dealt with fatalities caused by people sticking their heads out of windows.
One example immediately springs to mind of a Regional Railways Railway Manager who put his head out of a Stourbridge bound train one night and was struck by struck a bridge, causng death. This occurred in the late 80s.
The North London Line for example still has limited clearance alongside the train, which was the reason why the NLL 501s all had bars across the door droplight windows.
A few other facts about which people may wish to be aware, before they take advice from other people.
1) Objects from the track/trackside can and do get swept up by the windstream of the train and strike anyone who has gotten their head out the window.
2) Network Rail's cutbacks mean that at many locations, trees and bushes now intrude over the cess and close to the sides of trains. The growth will stop about the kinematic envelope, your head will pentrate outside of that and into the vegetation.
3) Temporary structures, such as scaffolding, workplatforms, OHL screening, etc may be installed and can come out to or intrude into the Structure Gauge.
4) Certain lines such as the WCML former London Division and the former GW broad gauge areas which have been four-tracked, have substandard six-foot and 10-foot clearances. A number of other lines, such as the NLL mentioned above, have minimal-clearance lineside structures.
It is therefore NOT perfectly safe to put your head out of the window as has been suggested, and doing so can result in Prosecution.