Corrections has yet to decide if it will appeal, but conceded that implementing the policy was a "serious challenge".
However, despite the ruling, prisoners still cannot smoke because the Government amended Corrections regulations to make tobacco and related products contraband and the court ruling was not about those amended regulations.
Corrections Minister Anne Tolley said: "The smoking ban in prisons has been a great success and there is no way we are backing away from it. Prisons are safer and healthier places for staff and offenders, and if we need to change the law to maintain this then that is what we will do."
Justice Gilbert said a blanket smoking ban did not serve the purpose of ensuring custodial sentences were safe, secure, humane and effective, and was not "reasonably necessary" to maintain safety of prison staff and inmates.
"In my view, the ban falls outside the scope of the rule-making power under section 33 of the Corrections Act." He added it was inconsistent with other laws.
The judge said it was well established in common law that prisoners retained all civil rights, unless removed by law, so the presumptive starting point was that they had the same rights as other citizens to smoke in their own home.
"The prison cell is the institutional equivalent of a prisoner's home."
The general manager of prison services, Dr Brendan Anstiss, said smoking had been very common before the ban and had contributed to poor health for staff and prisoners, whether they were smokers or not.
"There were a substantial number of incidents involving prisoners using lighters or matches to start fires, trigger smoke detectors, smoke illicit drugs, and make weapons."
Dr Anstiss called it "a courageous decision" and said Corrections "remained passionate in our belief that we could change lives".