The ruling came on a petition filed by Mulla Afroz; the top court said that the power of detention had been “illegally exercised”