This David it the actor here, and good to look at his actions themselfs not to side what ever reasoning (which is very, very risky, not possible to trace and judge anothers current but changing situation)
My person would not side with anybody but with what is skillful and not unskillful. Thiefs question is also not really clear, since the hungry person seems not to be an actor in this sample at all. So also the owner of the bread isn't, but simply this David, who obiviously harmed on one side to help on another, acted unskilful for the sake of "good", for gain, possible for priese of certain people, or to harm other, in the best case, lets say he acted foolish, like a child that wants but does not know how, unwise.
So again simple: taking what has been not given harms, and therefore not of good for oneself and all others, for peace and freedom of conflicts. Giving of what one owns, at the proper occation, and hunger is one of the five, is skillful.
Doing bad for the sake of good is foolish or even lordy, for whom is in the case of not being a proper case for giving would be worthy to help (not to talk about even to harm)? Think: of whom to help, even whom to harm, the mouse or the snake? Both never satisfied, both not dear to harm and kill.
It's good to side simply actions and tendencies. People are not for sure as long as not freed. Stick with simply precepts and what is praised by the wise, Thief. Otherwise thief may find his beloved friends and relatives lying on his battlefields death one day and would have not easy a way to overcome this transgressions done in the past, out of not knowing.