A trade group, the School and Nursery Alliance Ltd, brought a successful judicial review against regulations and guidance from the Scottish Ministers over the scheme.
Young children previously received a third of a pint of milk daily when they attended nursery or other childcare settings, such as childminders, with funding provided under a UK scheme, the Nursery Milk Scheme, before August 1 last year.
But on that date the Scottish Ministers replaced it with a new Milk and Healthy Snack Scheme, which also allows for children to receive a healthy snack, such as fruit, and non-dairy alternatives to milk.
It also altered the method of funding. The UK scheme reimbursed the childcare settings the actual costs of providing the milk to children. .
Under the new initiative funding is provided by periodical payments made in advance to councils based upon a local serving rate (LSR) set by the Scottish Government for each local authority.
A judge said: "It is the LSR which has proved to be controversial and which is the subject of this petition for judicial review."
The School and Nursery Milk Alliance represents dairy, health and education sectors relating to the provision of milk and non-dairy alternatives with its members specialising in providing the products to young children.
Lord Braid said: "It asserts that the scheme has resulted in funding cuts for many settings, which has in turn had a detrimental impact on the petitioner's members, by reducing their ability to compete in the market, so reducing competition."
It claimed that there were failures in the consultation exercise undertaken by the Scottish Government and irrationality in calculating the LSRs.
The hearing at the Court of Session in Edinburgh heard that under the previous scheme relatively small childcare settings located in rural areas, which tended to face higher costs for delivered milk, were not left out of pocket.
Lord Braid said: "The petitioner asserts that the new scheme, in particular the use of LSRs and the rates at which they have been set, has had a detrimental impact on the market for the supply of milk."
The judge said: "A number of settings have complained to the petitioner that the cost of acquiring milk from agents is no longer covered, and that they are faced with a choice between covering the shortfall themselves, or purchasing from other suppliers such as supermarkets, diverting staff resources to carrying out that task."
"The petitioner asserts that the scheme has had the opposite effect from that intended, in that it reduces the incentive to buy from local suppliers," he said.
One dairy firm representative believed that some childcare settings, particularly childminders, have chosen to stop giving out milk because of the burden of the new scheme.
The alliance maintained that it was not told of the proposal to base payments on LSRs or its rates until it was too late for it to make meaningful representations during the consultation process.
The Scottish Government maintained that there was a full consultation exercise on the principles of the scheme, including being taken over by local authorities.
But Lord Braid said he had decided that the consultation process, at least over the way the LSRs developed, was unfair and that the legal challenge to the regulations and guidance over a lack of proper consultation must succeed.
He said the new scheme was unlawful in that the ministers did not undertake a proper consultation on a key aspect, the LSRs, and the fixing of the funding for providing the daily milk and snack.