All battles stop after 100 rounds.
If noone wins by that time, then the credit for the win goes to the defender.

This most often happens when the attacker doesn't have enough damage to get through the walls after defeating the defenders.
The walls are still standing even though the troops are defeated, therefore the attacker loses.