Nearly 400 people have been sentenced in Nigeria for links with militant Islamic groups following mass trials.