When battling an NPC Trainer if you have the `Generation` and `Special Evolution` settings set to either be both `World Setting` or `both` and `World Setting` if that NPC has a pokemon capable of mega evolving in the first slot the NPC will mega evolve the pokemon and then on the following turn the NPC will Dynamax whatever pokemon is currently battling, yes this can be the mega from the previous turn as shown in the img attached, if the NPC starts with a pokemon that cant Mega evolve then it will Dynamax that pokemon then if one of its remaining pokemon can Mega evolve after the Dynamaxed pokemon has fainted it will Mega evolve that pokemon.
Dynamaxed Mega Venusaur:
https://imgur.com/a/CmnpseS