In a damning decision, senior judge, Mr Justice Dove, said the government had "closed its mind" to fracking objectors' views during a consultation exercise.
And it gave "no consideration at all" to scientific evidence casting doubt on government assumptions that fracking will support a low carbon economy.
The ruling means that the housing and communities secretary, James Brokenshire, will have to consider afresh a crucial paragraph of the National Planning Policy Framework (NPPF).
Paragraph 209(a) currently recognises the benefits of onshore oil and gas development, including unconventional hydrocarbons.
It states that such developments benefit the security of national energy supplies and support the transition to a low-carbon economy.
And it goes on to give a commitment that policies will be put in place to facilitate on-shore exploration and extraction of hydrocarbons.
The paragraph was challenged by campaigner, Claire Stephenson, with the backing of pressure group Talk Fracking.
Mr Justice Dove said the government had put out proposed changes to the NPPF for public consultation in March last year.
Government lawyers said that paragraph 209(a) was included as a "cut and paste exercise" from a 2015 ministerial statement to Parliament and that the public were not being asked their views on the merits of the policy.
David Wolfe QC, for Stephenson, said the secretary of state already "had a closed mind in relation to the substance of paragraph 209(a) and had no intention of entertaining any change to the policy".
Upholding Stephenson's judicial review challenge, the judge said reasonable readers of the consultation document would have believed that they were being asked to comment on the substance and merits of the policy.
"The public were engaged in the consultation on the basis that the merits of the policy itself was included in the subject matter of the consultation," he added.
Ruling that the consultation exercise was neither fair nor lawful, the judge said: "The secretary of state had a closed mind as to the content of the policy and was not undertaking the consultation at a formative stage. He had no intention of changing his mind about the substance of the revised policy.
"He did not consciously consider the fruits of the consultation exercise in circumstances where he had no interest in examining observations or evidence pertaining to the merits of the policy.
"This had the effect of excluding from the material presented to the minister any detail of the observations or evidence which bore upon the merits of the policy."
The judge also upheld arguments that, in adopting the policy, the secretary of state failed to take into account scientific evidence put forward by Talk Fracking.
Wolfe argued that the paragraph "failed to give effect to the government's long-stated policy" to reduce greenhouse gases.
The court heard that paragraph 209(a) was indirectly based on a 2013 scientific report which concluded that shale gas emissions were similar to those of conventional gas, and lower than those of coal or liquefied natural gas.
That led to a written ministerial statement in Parliament in 2015 that fracking promised substantial benefits and could help meet secure energy supply objectives, foster economic growth and lower carbon emissions.
The government's view was that fracking could "create a bridge" to maintain energy supplies whilst renewable sources are further developed.
But Wolfe said that, by the time of the ministerial statement, there were "already concerns about the correctness" of the 2013 report.
In a July 2016 report, the Committee on Climate Change said there was "considerable uncertainty" about the impact of fracking on greenhouse gas emissions.
That report stated that fracking on a significant scale would be incompatible with the government's commitment to reduce greenhouse gas emissions by 80 per cent by 2050.
Talk Fracking also relied on a February 2017 report by environmental expert, Paul Mobbs, which made detailed criticisms of the science underpinning paragraph 209(a).
Wolfe argued that the secretary of state "gave no consideration at all to the disputed scientific material, and therefore left out of account what was an obvious material consideration."
Also upholding that ground of challenge, the judge said: "The secretary of state's evidence makes clear that this material was not considered. He left out of account obviously material considerations relevant to the decision which he had led the public to believe he was taking."
However, the judge rejected a parallel challenge brought by charity Friends of the Earth, which claimed that the secretary of state had been obliged to carry out a full strategic environmental assessment before adopting paragraph 209(a). A hearing took place in December.
The judge gave the secretary of state time to consider the implications of his decision in the hope that an order giving effect to his conclusions could be agreed.
Last month, the communities secretary refused plans for a shale gas fracking site near Preston in Lancashire after concluding that the scheme would have a "very significant adverse impact" on road safety, despite attaching "great weight" to "the benefits of onshore oil and gas development".