In the great majority of cases the context alone will suffice to show whether "what?" or "who?" is the more apt translation of ko. In your second passage, for example, clearly "What?" is needed, for the answer to the question is a mode of behaviour, not a person.
In cases where either translation might arguably make sense, the translator will probably base his decision either on (1) His knowledge of typical/natural ways of framing questions in sutta usage; it will sometimes happen that one of the two options, though semantically possible, would amount to an inelegant or unnatural way of phrasing the question; (2) His knowledge of Buddhist doctrine.
In the case of your first passage, if "What?" were used in place of "Who?" then it's hard to see why it would be an "unfit question", for elsewhere in the suttas we do find the Buddha saying things like "contacts contact," "feeling feels", etc., and so it would actually be an easily answerable question.
“Keep to your own pastures, bhikkhus, walk in the haunts where your fathers roamed.
If ye thus walk in them, Māra will find no lodgement, Māra will find no foothold.”
— Cakkavattisīhanāda Sutta