Please note here that krishna got 8 boons from shiva. It is written in bhagavatham. One of the boons is that krishna must win all his enemies and that all his enemies must be destroyed by him. So in the banasura fight, banasura called shiva down to fight narayana(krishna). Here shiva becomes an enemy of narayana. Thus, according to the boon he gave, he has to lose. Moreover, banasura has to be killed by krishna as he is the oni one who can beat banasura.
These are the lilas of both narayana and shiva. They are one. vishnu worships shiva and shiva worships Vishnu. Please keep this mind.
Krishna says the bhagavad gita to arjuna as God and not as Krishna. Please remember this. As GOD, he encompasses everthing. As Krishna, he is just a mere avatar of vishnu.