TOCs always maintain that food provided on board (buffet or trolley) never makes them a profit. Not sure how they calculate that as of course there are various other aspects (eg if buffet space, could it be given over to seats that they can fill instead etc) - but of course there are staff costs, sales levels, stock control, waste etc etc. And thus providing food on board is part of the 'offer' and it may not actually make money. In that scenario - if true - then they will be keen to charge maximum price to try and reduce the loss of the facility. I suspect main cost is wages, as of course they would not pay rent to provide a trolley themselves on a train. This will be a different calculation for trolley only products as no cooking / food prep area is required (ovens, counters etc)
On stations: in the 1980s I worked for travellers fare on a station. That was part of BR so if they paid a rent it was a notional rent for accounting purposes (as opposed to WHSmith on the station who would have paid a commercial rent for their premises to BR).
The TF Unit managers office had a table showing percentage profit for each item sold on the menu. I assumed this was calculated at HQ. It was notable that the maximum profit margin was broadly speaking on the cheapest items (eg cups of tea) - production cost being a low percentage of the sales price. I bet bottled water fits this pricing model - don't think much of that was sold in the 1980s! It was not a travelers fare sales line in our unit IIRC. The lowest profit margin was on the most expensive items (eg a hot cooked meal product).
This of course gives rise to the 'selling up' that all will be familiar with - ie when you buy a product you are offered by the person serving something else, which if done skillfully will be a high percentage profit product, eg customer buys a cake and are asked if they would like a cup of tea to go with it? ('do you want fries with that' will not be asked because they think fries goes esp well with what you ordered, but because they make more money on fries).