Afghanistan's Defence Ministry says it has detained and sacked hundreds of its soldiers over a series of insider attacks on foreign troops.