I'm speaking from a standpoint of an English speaker rather than a language expert so experts can chime in.
As a teacher, when I am discussing certain behaviors with my students, I would say "why would you do something like that?" In this context, I'm not really demanding an answer but making a point of explaining why certain behaviors are not acceptable. So it is like a rhetorical question, a question that does not really require an answer.
But if I demand an answer immediately for something that they did , I would say: "Why did you do that?" This time, the student has to give me answer because I am asking a question directly.