The Department of Internal Affairs (DIA) let pokie machine operators break government regulations for 17 years because it had created rules for them that contradicted the law.
Emails released to RNZ show DIA staff discussing the "illegal" arrangement, which was only made acceptable in Covid-19 response reforms.
Operators said they raised the issue with the department many times, but it was never a priority.
Gambling regulations brought in by DIA in 2004 stipulated all available net proceeds from gaming machines must be paid out as community grants.
However to do so would mean some organisations would technically be trading as insolvent - a breach of the Companies Act and of the requirements to be financially viable in the Gambling Act.
As such, on an ad hoc basis, the department let organisations hold on to extra funds as a buffer. The exact amounts are unknown.
A DIA spokesperson told RNZ the solution was pragmatic, but policy staff - in emails released to RNZ - didn't think it was actually allowed.
"There have been long-standing issues with the annual financial viability assessment of societies. These issues have been exacerbated over time by allowing for ad hoc increases in an 'equity reserve' which breach accounting rules (and have caused additional inefficiencies for both the sector and the department), and a withholding of money that should have been returned to the community," one staff member wrote.
"Some societies continually agitate for lower return to community and have gained concessions," a second said.
"There appears to be no legal basis for DIA allowing any retention of undistributed net proceeds," a third said.
The department had the informal arrangement in place for 17 years.
Gaming Machine Association NZ chair Peter Dengate-Thrush said the agreement was an understanding that DIA would not enforce its own regulations and nothing illegal was happening, although he said the sector did want a proper resolution.
"The industry would bring this up with the department as one of the many things the department, in the industry's view, wasn't doing very well.
"So there's a number of things the industry brings to the department's attention and ... this was one of them."
He said it was not unlawful.
The emails from DIA staff also set out frank opinions from one policy advisor on the state of the pokie sector.
The advisor described the sector as unsustainable and unstable, that community benefit was not maximised or evenly distributed, and pointed out gambling proceeds do not benefit communities from which they are drawn, the email said.
The advisor also said there was a strong case for rationalisation - something David Hay, a former advisor on class four gambling at Auckland Council, agreed with.
"Thirty or 40 of these pokies trusts, we would probably get away with 3 or 4 ... they would be so much more efficient, they would be easier to regulate.
"There's no reason for them to have this great diversity of basically amateurs getting together and saying let's run some pokie machines to support bowls or darts."
But Dengate-Thrush said there was no need for rationalisation and that the staff member's views were irrelevant.
"Be aware that there are zealots inside some of the government departments with views. Fortunately these views don't materialise into policy unless they've been through a detailed community consultation."
DIA gambling regulations were finally changed last year following the Covid-19 lockdown, meaning organisations can now retain their reserves, to 1.5 times their liabilities.
Pub Charity is one of the largest operators in the country, and chief executive Martin Cheer said the clarity that had been established was better for everyone.
"If anyone has accumulated cash beyond that ratio then they are in breach of the regulation - it should be much easier to administer now."
Operators must pay out at least 40 percent of the cash proceeds from gaming machines as community grants, although that threshold was scrapped for the current and previous financial years, due to the Covid-19 pandemic.