It happens when war cuts off crude supply or a drought shrinks the harvest. Raising rates makes borrowing dearer and cools demand, but it does not put back the barrels or the grain. That is why central banks hesitate in front of a supply shock. If prices stay high long enough, though, people start expecting them to keep rising, and from that point it becomes a problem rates have to handle.