The key is to understand there are energy producers and energy retailers. Some have the same name (e.g. Shell) but the producing and retailing arms are are being run as different businesses.
Energy producers (Shell, BP, Centrica) produce energy and sell it to retailers. They use an auction type sheme in which energy is sold to whoever will pay the most for it on a global scale. When there is less energy being produced across the world (because Russia ain't pumping gas) then prices get high.
The retailers (Octopus, Bulb, Gritish Gas) buy that energy and resell it to us.
Ofgem review the cost if buying that energy and set a cap for how much it can be resold for. This is to prevent retailers being able to buy at low prices and make £££ by selling it to us at high prices. However, as we're seeing, it's useless when the wholesale cost of buying that energy gets very high.
So the producers are making billions of pounds of profit. But they are not selling to us, they are selling to retailers. The retailers are having to pay those very high prices and then resell to us no higher than the cap. So they are making very little profit or, as is happening now, a loss.
As wholesale prices keep rising, the cap keeps rising.