Supply and demand are important for the law of value to operate dynamically. We can make a distinction between the actual prices in a market, the market prices, which fluctuate due to supply and demand, and the prices which allow for an economic system to reproduce itself. The latter are called prices of production or natural prices. The market prices fluctuate around the prices of production, there is a gravitation of market prices toward the prices of production as others have mentioned. Or, in other words, the prices if production serve as the attractor.
The prices of production are given by values (and there is a whole question of the transformation problem on how to go from values to prices of production - this is a topic worth its own post).
In Capital Marx studies a capitalist system where the prices are given by their values. There is no price fluctuation due to supply and demand and the prices are at their natural price. Remember that the natural price, or the price of production, are those prices that allow for an economic system to reproduce itself (or if we want to extend it, expand with some given growth rate). These natural prices can be seen as structural.
Even without introducing fluctuations due to supply and demand, and by using natural prices, Marx showed that surplus value (think profit) exist even when capitalists buy and sell commodities at their value. Aggregate profit doesn't derive from arbitrage nor have its source in temporary price fluctuations. It is because labor creates more value than it is worth, or bought for at its value. Surplus value has its source in production.
That there is a transformation from value to these natural prices or prices of production is one aspect of the law of value. I'll call it the "static" aspect of the law of value.
The above is shown without introducing supply and demand. But supply and demand, and hence the fluctuating market prices, does have a role in the "dynamic" aspect of the law of value assuming that capital and labor are mobile and can be reallocated to different economic sectors and there is sufficient competition. This dynamic aspect of the law of value explains how price fluctuations around natural prices can serve as signals which reallocate our social labor to meet (or get closer to) demand.
Supply and demand comes in to play in the following way: if a commodity is underproduced (not enough labor is allocated to produce that commodity) then its demand outstrips its supply. Its market price then rises above its natural price (or value) as bidders compete. The rise in the commodity's actual market price vs its cost to produce means that there is a temporary increase in profits to be made by producing and selling this underproduced, and hence "overpriced" commodity. This increase in profits is like arbitrage. It is temporary and caused by a market fluctuation in the price. The increased profits that can be made leads to an increase of investment, or capital, by others in producing this commodity. This also means an increase in the labor that is reallocated to produce this commodity. Fluctuations in marker prices impact temporary profits, which impacts investment, which reallocateds labor. This is the dynamic part of the law of value.
The opposite scenario also reallocates labor. An overproduced commodity (one where too much labor is allocated toward producing it) causes supply to outstip demand. This leads to a fall in prices, hence a fall in those temporary profits, and hence a flight of investment/capital from the production of thay commodity. And a flight of investment means that labor is reallocated away from that sector.
And notice these two scenarios work together. An underproduced commodity can become overproduced as more capital (and hence labor) is allocated toward sectors that produce it. And vice versa. They create a feedback system that causes the turbulent gravitation of market prices around their values.
So supply and demand impact market prices, which lead to a reallocation of human labor so that supply can meet demand. And that is accompanied by market prices gravitating around the natural prices, or prices of production, which can be given by (a transformation of) values.
This is a "dynamic" and "static" aspect of the law of value.