“Mój przyjacielu” here is the vocative form. Vocative is a rarely used case whose purpose is addressing other people. So a child calling their mom would usually use the vocative form “mamo!”, same for an interjection like “my friend” here.
For many nouns, the vocative form is the same as the nominative case. One example is the expression “Panie i panowie!” (“Ladies and gentlemen”), which technically is in the vocative case, but looks just like it would in the nominative. Some people say the vocative case will become completely obsolete in the next few decades, just as it did in Russian quite a long time ago.
In fact, the sentence here lacks a comma, which should appear before the form of address: “Dlaczego to zrobiłeś, mój przyjacielu?”. I suppose that if it was there, you wouldn’t have any problems deciphering the actual meaning. If you wanted to say “Why did you do this to my friend?”, you’d have to use the dative form: “Dlaczego to zrobiłeś mojemu przyjacielowi?”
Here’s an explainer on the vocative case: http://mowicpopolsku.com/polish-grammar/cases/vocative/