What went wrong in this position? What can I do to improve my gameplay with the black pieces?

There's a lot of small things I could turn into a lesson, but here are some of the larger points:
5...Be6? was a mistake, but it was difficult to find a good move here. This move loses a pawn if it goes: 5...Be6? 6. Nxe6 fxe6 7. Bxe6, but I imagine you saw the pressure on f7 and couldn't find a way to hold. A thematic defense to these attacks is ...d5! In this case, it could work such as 5...d5! 6. exd5 cxd5 7. Bb3 Nc6 and black just continues to develop pieces while holding control of the center.
11...cxd5 would have been better because it replaces your pawn duo in the center. Again, this is one of the key opening principles:
https://www.chess.com/blog/KeSetoKaiba/opening-principles-again
14...Bg5? would lose material if lots of trades happen on g5.
16...Qd6?? was the last big error because it hangs the a6 knight. Better would have been 16...Nc5 to save the attacked knight, or fancier would have been 16...Bxc1 17. Rxc1 (to decoy their rook from attacking a6) and then you have time to relocate the knight such as 17...Nc7.

First you shouldn't blunder a knight but you are sevenhundred that just happens and the bishop trade wasn't good practice some openings an play lots of chess

What surprised me was White not playing a early d4 to play the Hanham Philidor. KeitoSaba is correct that the counter thrust in the center is far better. You also see this in Italian games but typically if White has the Bc4/Ng5 setup. Since Black plays half a move down from the onset, I'd make White earn every square he fights for. Think of it like this: for every move made you get something from the position but you also give something to your opponent as well. Therefore, try to find the moved that give you more than your opposition gets and you'll see improvements in your games.

The Philidor is perfectly playable for both sides, so there's nothing wrong with your 2. ... e5.
One small opening wrinkle is that you could play Be7 FIRST, before playing Nf6.
That way, White cannot try that dumb Ng5 move (because your Bishop and Queen both guard the square) and once you do play Nf6 you can simply reply to Ng5 with Castles.