
Mega Magearna is one of the several new mega evolutions in Pokémon Legends Z-A, added as part of the Mega Dimension DLC, and you can add it to your squad by reaching the endgame.
The Mega Dimension DLC has its fair share of quests to complete, which begin after you have finished the main story. One such quest will introduce you to Magearna, and you'll also get a clue about how to mega-evolve it.