If you quit, lose connection, or the game crashes, it counts as a loss. Presumably, when you start a battle, it notifies the server, and the server basically counts it as a loss unless it receives a message from the client that you won the battle.
It’s not clear how often the client synchronizes leaderboard data with the server, but I know the devs have said there’s a delay: