Under the rail franchise agreement during the bid process, the terms might mandate that journeys from A to B cost £10, and that journeys from B to C cost £5. There might be no obligation to price travel from A to D via B & C at a particular cost, so a rail operator might make that more expensive.
It’s silly from the consumer perspective, but it makes sense for the rail operators to do this in order to maximise profits.
There's no negotiations between the companies here, though they could ask the regulator (the ORR) to intervene if they believed the algorithm gave unfair results.
In real terms the main reason is to protect commuters and capacity - as a theoretical made-up example during the bid process they might be aware that lots of people travel from Milton Keynes to London so the council wants to put a cap on increases for that route. They might also still have lots of capacity on the route from Banbury to Milton Keynes on a morning, so that is priced much lower than Banbury to London. So if you go Banbury -> Milton Keynes you might get a “discount” for not a lot of people using the line, and travelling from Milton Keynes -> London you get the rate that’s protected for commuters, but if you go between Banbury and London then part of the route is already at capacity and there is less discount on the rate.