The meaning of 'Why would you do that?'

Why did(do) you do that?
Why would you do that?

Do they have different meaning?
If so, please help me understand that.

Also, can ‘would’ be used when you express ‘expections’?

I’d really appreciate your answer.

If you did something (in the past) and someone else wants to know the reason he/she will ask: Why did you do that?
If you intend to do something (in the future) and someone else wants to know the reason he/she will ask: Why would you do that?

Don’t we use ‘Why would you do that?’ to express our belief or doubt with a surprise?

He: I should not have that rude with her.
She: Why would you do that? (I believe you, you can’t do that – with a less surprise)

He: I should not have that rude with her.
She: Why would you do that? (I did believe you, but now I don’t – with a great surprise)

We do. It all depends on CONTEXT.
There are many ways to ask a question or express a thought. I gave a very general answer to a general question with no context.

con·text n.

  1. The part of a text or statement that surrounds a particular word or passage and determines its meaning.
    2. The circumstances in which an event occurs; a setting.
    -Context - definition of context by The Free Dictionary

Thank you, Milanya.
I’m sorry for not having given you context. I heard that ‘why would you do that?’ in sitcom ‘Friends’ and I didn’t know how to put the situation in my English. :frowning: In that situation, they didn’t mention something for the future but I think there was some intention to do something. I think I understand now. Thanks again. :slight_smile: