This can be an incredibly frustrating glitch when it occurs as it often means that you are going to loose a gym battle and all of your Pokemon will get knocked out. This glitch occurs during gym battles. You have worked to take down all of an enemies health, but the Pokemon can’t be defeated. The battle will only end when you die, or after a long delay and the game finally registers that you have defeated your opponent.
This glitch appears to be caused entirely by the server performance, but could also be down to your network connection. Due to the troublesome nature of the servers, it’s highly likely to be a server issue. There is currently no known way to resolve this as the game servers cannot be altered by the game while a gym battle is taking place. We hope that the games developer will eventually release a patch to handle the event when the enemy Pokemon has been defeated to stop them taking any more health from you.