When a child, Midoriya didnt have any quirk. And at some point he considered Bakugo his friend. Why then Katsuki Bakugo felt threatened by Midoriya? This makes sense when Midoriya already had the One for All quirk and could be an obstacle for Bakugo to become the greatest hero (which is Bakugo's goal), but I can't understand why Bakugo was so mean to Midoriya when he was quirkless. Is there any explanation about this?
Katsuki Bakugo throughout all of My Hero Academia has a superiority complex, this is made evident by his lavish demands of not only Midoriya but also his friend group at the start. It's quite simple to tell he has this characteristic, as he is portrayed as being egotistical, arrogant and narcissistic. This kind of behavior has two spectrum's too it in character development winning or losing at the start he's higher in the pecking order thus he strikes down anyone as to show his superiority and fuel his own narcissistic traits. He specifically picks on Midoriya as he wants the admiration of his peers as being the strongest, if he picked on someone else it would be almost like saying they were stronger and he wouldn't potentially gain there admiration. Another take would be that Midoriya being born quirkless is actually kind of rare as there is always the potential for him to suddenly activate a quirk at any time, this unknown factor is a reason for katsuki to be unsure of if he's at the top of the pyramid, thus he bully's him to make sure he also believes he will never be strong.
This question as a whole is interesting because I believe there is a strong psychological meaning behind all of this that adds a whole dynamic to there relationship throghout the story so far.
In the episode Katsuki Bakugo: Rising, Bakugo answers this very question in his own words. Unsurprisingly, it corroborates what I previously said. In a flashback while talking with All Might, Bakugo, speaking of Midoriya, says (emphasis mine):
The thing is, [Midoriya] doesn't think about himself. He never has. Even now, with everything he can do, that still hasn't changed. It always freaked me out. That's why I pushed him away. But as a kid, I didn't recognize my own weakness. So I bullied him.
All Might further points out that Bakugo is so willing to train with Midoriya in order to make amends, though Midoriya likely believes Bakugo has nothing to make amends for, not seeing the situation in the same way. These points might help to combat my own complaints that I levied in my answer below.
There is an even better quote from Bakugo in the episode Deku vs Class A, when he apologizes to Izuku:
Our whole lives, I've looked down on you. You were quirkless--obviously way behind me. But somehow, it felt like you were ahead of me too. I hated that. I hoped you'd disappear. I didn't want to accept you. So I bullied you. To make sure you'd stay away. I had to reject you. So that I could feel superior. I needed to win--to beat you. And we both got into UA, where not a single thing played out the way I wanted it to. Every day, I was forced to see how strong you were. And how weak I was. Saying this out loud doesn't change a thing. But that's how I feel... Izuku. I'm sorry for everything.
As can be seen, Bakugo's explanation here still matches up neatly with mine. He initially views Midoriya as inferior. Due to Midoriya challenging this belief when they were kids, Bakugo feels threatened. He goes into denial, gets angry, and bullies Midoriya--both as a means of pushing him away (because he represents something scary) and reaffirming his own assumptions of superiority. And it's only after Midoriya repeatedly proves Bakugo wrong that he is forced to accept that his worldview is incorrect; this is when he finally accepts Midoriya.
This is simple child politics. As someone without a quirk, Midoriya is an outlier (someone different, an outsider to the group) and Bakugo is a bully. This bullying is exacerbated by two causes: First, Bakugo is egotistical; he is vocally conceited and aggressive; he is confident that he's got the greatest quirk ever, and certainly better than all his classmates, and he lets them all know it. Picking on the quirkless Midoriya is a natural way to affirm his superiority and establish the pecking order, with him on top and Midoriya on the bottom. Secondly, Midoriya has the absolutely ridiculous notion that he wants to be a hero even though he doesn't even have a quirk. Even adults like All Might tell Midoriya it's not possible and he should just aim for being a police officer, and kids sure aren't going to be as nice about it. Of course they're going to bully him, and Bakugo, as the top of the hierarchy, is going to lead the pack. In his mind, Bakugo has to beat Midoriya down to let him know his place. Midoriya's dream is actually a threat to Bakugo's world view, so it makes a lot of sense.
And because it's human nature, any deviation from Bakugo's expectations is just going to make him angrier and make him bully Midoriya even harder. For example, we see this during the times Midoriya tried to help Bakugo out as a kid. Bakugo gets angry, because why would he need help from a "loser" who is so far beneath him? Accepting that kind of help would establish Midoriya as having worth and would also diminish Bakugo's self-worth. And it is in these moments when Bakugo's resentment and hatred of Midoriya sprouts and grows, festering until it culminates in the explosions of anger we see during the series when Midoriya proves he actually can be a hero, and thus has worth. At this point, Midoriya becomes a serious threat to his world view, and the natural human response is to lash out in anger and keep on denying reality.
On a side note, I think this question warrants mentioning another thing about Bakugo. He's literally mean to everyone. Is there any point during the series where he isn't verbally abusive? While his classmates often don't seem to mind, he never tones it down, and he's so bad that the teacher's have to warn him that he shouldn't be talking to people he's saving like that.
A better question is why on earth Midoriya considers Bakugo to be his friend in spite of all of this. Midoriya could have some genuine admiration since Bakugo shows leadership qualities and has a cool quirk, but honestly, this isn't a great explanation. I think this break from reality and suspension of disbelief is better explained by this just being typical Shonen genre tropes, in always equating rivalry with friendship. (For example, see also Sasuke and Naruto, who the story suddenly declares to be "best friends" after being antagonistic towards each other for the entire original Naruto series. And more relevantly, Goku and Krillain in Dragon Ball, where Goku is basically too dumb to realize Krillain is bullying him and somewhere along the way they become friends.) The main themes of the Shonen genre are friendship, hard work, and victory, and things tend to be seen through these lenses. And the rival character is a staple of this. Even when they're an outright bully like Bakugo, they somehow get designated as a friend. See Bully Turned Buddy and Rival on TV Tropes, which both use Bakugo as an example.