An inquest has uncovered serious mental health care failures linked to the suicide of a 17-year-old following bullying in military training.