I think that is quite interesting. It seems that only about 6 or 7 guards are affected by the captains training (I assigned almost my whole household as guards, but only some received melee / ranged stats. And there were more than 6 with low enough stats to be able to receive training benefits) but i couldn't find any obvious evidence for that in the code.
The relevent part in the code seems to be:
I think the reason, that not all guards are affected by training is, that the variables with _chance in their name are the same variable through the whole loop. But every guard with high enough stats to reduce training chance does reduce the _chance variables so that after the loop passed enough of your guards with high enough (>= 50) skills it becomes impossible for any of the remaining guards to improve their skills.
I think this is most likely a bug and not an intended feature. To fix this one could either move the initialisation of the random loops into the for-loop (would make the training sucess chance among slaves independent. Not sure if that would be intended and is possibly computationally a bit more expensive than it is now) or create copys of them and only modify the copys in the loop (would be closer to how it works at the moment)
My suggestion to change that part in the code would be:
So
GD-studios feel free to edit this part of the code the way i suggested so that skilled guards don't have a negative effect on other guards training chances (if they are before them in the $npc list, which i am not sure how it is ordered) in the next version of the game.