Yeah, you have to complete every single level in the game, and then when you fight this guy, he has a secret 3rd form instead of just 2 forms, and you get a better ending.
actually, he got the bad ending because he fought the final boss at Zone 5-J, however, if you fight the final boss at Zone 5-I, you will get the good ending
it's because this is the "fake" final boss, the true final boss has 3 forms, the fake final boss is fought at Zone 5-J, but the true final boss is fought at Zone 5-I, defeating the fake final boss will give you the bad ending, but defeating the true final boss will give you the good ending