It's true that in a competitive Pokémon battle, which takes place outside the game, you would have won that match.
However, in-game battles function differently. As stated in the comments. Because a draw means you have no Pokémon who can battle, the game treats it as a loss. Otherwise it would cause issues. In modern Pokémon games, exceptions are made for a majority of rival battles, where your Pokémon is healed after battle. This just happens to be one case where it isn't true. Because this isn't really a rival battle, it's the Champion battle.
The fact you lost isn't a glitch. Although you might consider the screen's premature fading to black a glitch.
Here is an example of what it should actually look like when you get a draw in a Pokémon battle. Clearly this battle is programmed to fade to black when Nemona loses her last Pokémon, for cinematic effect, and GameFreak forgot to check for a draw, so it resulted in this awkward ending. You still lost the battle.