Optimum Y is not related to X, but the price when you replace the stock. ( let's say X2 ) When supply has problems, or economy is unpredictable, it is harder to predict X2, so usually your estimation is a bit off.
So you have to have bigger margin to cover for this estimation error. ( assume the worst )
(Yes, equilibrium economics is a joke even when law of big numbers is involved.)
The real answer is that when inflation is happening, it provides an easy excuse for raising prices far beyond the cost of your inputs. Everyone expects prices to go up, so they don't balk at yours going up faster than inflation.
It's one of those simple macro-econ models that sound good, but never play out in real life because humans aren't calculators. The reality is a mix of both, probably more of your explanation.
Critically higher profit margins doesn’t necessarily translate to higher profits because you’re selling fewer goods.
Remember, prices generally are a function of the cost the market will bear. If the general public will pay more for something, why not rise the price? If everyone is rising their prices at the same time, you have less pressure to compete on prices.