The five-man bench of the court ruled the detention breached the right to personal liberty in the PNG constitution.
There are 850 men in the detention centre on Manus Island, about half of whom have been found to be refugees.
The Supreme Court has ordered the PNG and Australian Governments to immediately take steps to end the detention of asylum seekers in PNG.
"Both the Australian and Papua New Guinea governments shall forthwith take all steps necessary to cease and prevent the continued unconstitutional and illegal detention of the asylum seekers or transferees at the relocation centre on Manus Island and the continued breach of the asylum seekers or transferees constitutional and human rights," the judges ordered.
In one of two lead judgments, Justice Terence Higgins said the detention also breached asylum seekers' fundamental human rights guaranteed by various conventions on human rights at international law and under the PNG constitution.
Australia is saying they will not take the refugees back. But they're Australia's responsibility. There's also the question of compensation from the PNG government for years of unlawful detention and abuse (and, potentially, from Australia's corporate subcontractors, who did the actual detaining and beating). But Australia will probably try and walk away from that too. Which is hardly going to encourage other countries to deal with their mess. Which means that Australia will have to admit responsibility and start dealing with refugees again, rather than trying to shove them out of sight, out of mind onto its poorer neighbours.