It was a safety measure introduced to increase visibility of approaching trains to track workers and reduce/prevent fatalities. With the introduction of much quieter diesel and electric locos in the 60's it was much harder to pick up approaching trains and at the time other than traction on a few very specific routes, no UK locos or multiple units were fitted with high intensity headlights.
It's to improve the visibility of a train (basically like a hi-vis jacket), and was introduced in the 60s after they found diesel (and particularly electric) trains to be quieter than steam trains (note how even now, steamers don't have yellow noses). Remember, headlights on most British trains are fairly bad, so it's not like you'd be able to see the beam of the light.
As said, I am almost sure it's mandatory, I don't think the exact colour is mandatory but I guess there are regulations stating the visibility of the train. Similar regulations in Italy meant that this livery had to be changed First they got a red ugly band in the front, later this livery was adopted This was a problem to almost all rolling stock as the first version of the then new livery was supposed to have dark green fronts, so it was later changed A red stripe was made mandatory, and has been integrated either on the green front or more likely on a white/grey background I think the yellow nose must be caused by similar regulations in the UK.
There are similar regulations, you can read them here (if you register an account): https://www.rssb.co.uk/standards-catalogue/catalogueitem/gmrt2131 iss 1 I'm not sure if it requires an exact shade of yellow, or what the amount of yellow required is - Grand Central got away with a very small amount for years: For new trains (such as the 68 and Bombardier Aventras) don't require yellow fronts (although some still wear them, presumably through choice of the operator or person who designed the livery) as the headlights are bright enough to satisfy the regulations. (None of these images are mine)
It was 1m^2 of Yellow - 59s had just the buffer beams painted. Anything since the 700 is able to ditch the Yellow end providing it meets the latest lighting standards. The 345s were the first to drop it but it is now optional. Some TOCs have done it to match the existing fleet. Others (for example GA with a large number of user worked crossings) decided they'd rather have the super bright lights and yellow end) France also has a stripy front panel requirement - usually only enforced for open access - SNCF ignore it CP in Portugal also used to have Red/White stripy fronts. Ireland used to have high viz orange panels, before later switching to yellow So the UK isn't alone is trying to make trains more visible