Your confusion stems from the fact that you're not seeing the semantics at play in each language in those two sentences.
In English, we say "do something to someone" where someone logically is the indirect (dative, not accusative!) object, recipient of the verb do. However, in Russian, the semantics change; instead of doing something to someone, they act (поступать) a certain way with (с) someone.
In other words, your error here was expecting a dative based on English usage instead of parsing the Russian apart from the English.
Russian:
Как ты мог так поступить со мной?
How you could so act with me?
English:
How could you do this to me?
Same meaning — two different forms of expression.