According to Bulbapedia:
In order to Mega Evolve, most Pokemon must be holding their appropriate Mega Stone and the Trainer must have a Key Stone. Only Rayquaza does not need a Mega Stone to Mega Evolve; instead, it must know the move Dragon Ascent.
In the Pokemon XY anime, at the end of the first thirty or so episodes there is a short clip introducing all the of mega evolutions. Most of them are seen to be wild and mega evolve as they feel.
If they had a trainer but the anime didn't show it, fair enough. However, what about Mewtwo Y in the 16th movie, and Latias and Latios in the 18th movie, they definitely did not have trainers.
So how do they Mega Evolve by themselves?