A South African judge ruled on Wednesday that the detention of Mozambican former finance minister Manuel Chang over $2 billion of fraudulent loans was legal.