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.
The centre operators and PNG's immigration authorities have recently been trying to move refugees out of detention and into a so-called transit centre.
They are also offering them the chance to leave detention during the day under certain conditions.
The asylum seekers whose applications have not succeeded are unable to leave detention and are being told they must go back to their country of origin.
The Supreme Court decision means that both groups — refugees and asylum-seekers — are being illegally detained, because their freedom of movement is curtailed.
Comment has been sought from Prime Minister Malcolm Turnbull and Immigration Minister Peter Dutton.
Labor has also been contacted, while Greens immigration spokesperson Sarah Hanson-Young has called for all remaining detainees to be brought to Australia.
Senator Hanson-Young told the ABC “the game was up” and Mr Turnbull has to listen to legal and humanitarian experts.
“Really the Government now has no other option but to bring the people left there to Australia and allow them to apply for an Australian visa,” she said.
“They’ve seen two of their colleagues in the detention centre die, one at the hands of guards and another because he had an infected foot which became septic. These are people who have already suffered.”