Depression?? I'm confused

So with all the depression/suicides and people saying to "check on your friend/strong friend" I have a dilemma I would like to share and hopefully some of you can give me advice.

I recently came out of a relationship where my ex mistreated me. He was depressed and going through a hard time and whenever I asked him what was going on he would say "it's nothing to do with you, it's me." He treated me horribly and made me anxious and scared when talking to him. The way he treated me made me think I actually did something to him although I stayed and tried to be supportive and there for him as a shoulder to lean on.

With that being said, I made effort to check on him and be there when he was down.. I did that everyday even though I was mentally and physically  exhausted from how he was acting. So with all the talk about suicide and depression I'm just wondering why he chose to mistreat someone who tried to be there for him? He made it seem like me checking on him was a bother and sometimes he ignored my messages but was on social media and talking to other people but with me he was a jerk. It was almost as if my presence annoyed him 😔

I know that when people are depressed they aren't themselves but I don't think they mistreat people who are there for them? We haven't really spoken since we broke up and his silence is killing me although I've gotten used to it now.  I know people handle things differently but can someone tell me why I was possibly mistreated?