Welcome to the forum
I'm not sure of the origin of the word "diagram" in railway parlance but there were/are two meanings
A train/railway vehicle was built to a particular diagram featuring a particular design or electrical/mechanical arrangement. Have a look at some of the spotting books (e.g. Platform 5) and I think diagrams are listed in there relevant to the class/type of train
Secondly, as described upthread, a diagram is a particular unit/locomotive/train's working from one location to another. It may have a depot prefix and a number. So for example, SU803 is a Class 171 diagram/working from its base allocation of Selhurst Depot (SU). SU803 means that a particular 171 unit, e.g. 171.804 is working London Bridge-Uckfield services for all, or part of the day. Another example is BI704 which might be a Class 313 unit working out of Brighton Depot on Brighton - Portsmouth Harbour services. A further example would be HE056 which might be a Class 717 working out of Hornsey Depot between Welwyn Garden City and London Kings Cross/Moorgate
Usually, train diagrams are worked out by train planners based upon availability, miles, maintenance etc and there is never a guarantee that a train will stick to its allocated diagram on a particular day