A soldier died when his rifle went off “without warning” during a training exercise in the Scottish Highlands, an inquiry into his death has found.