Hi there,
I've experienced this bug plenty of times as well, but there's some missing information on how to reproduce it. Here's the steps and a video how to reproduce it:
https://screenpal.com/watch/c0XvoVVmoLQUser A leads with any pokemon, let's say Zamazenta. User B leads with any pokemon, let's say Volcarona.
Turn 1: User A goes for Close Combat versus Volcarona. User B can click any move.
Turn 2: User A swaps to any other pokemon, user B swaps to his mega pokemon.
Turn 3: User A swaps back to Zamazenta, user B mega evolves his pokemon and picks any move. This turn, Zamazenta will Close Combat the Volcarona again that is not on the field.
So in order for this bug to happen, the pokemon swapping into the mega must have made a move before in the battle.