South Africa’s government acted unlawfully in failing to give the Dalai Lama a visa for a planned visit last year, out of fears of angering its trading partner China.