Court documents detail the moment 12-year-old tried to shoot his teacher, but the gun failed to fire