How could you do such a thing?
It is a rhetorical question, one that does not expect an answer.
If could be said as:
What you are doing is awful. I wonder how you could even do it at all.
It is usually said in response to some bad insult or some awful act against another person. If a man touched a woman without her permission, she might respond with "How dare you!?"