Note, this only applies in Generation 6. As of Generation 7, turn order is determined after Mega Evolution instead of before like in Generation 6, so none of the following mechanics apply.
In most circumstances, Mega Pokemon will make use of their ability as soon as soon as they Mega Evolve. For example, Mega Tyrantiar's Sand Stream activates as soon as Tyranitar evolves. However, in some circumstances, this will not be the case.
There is a hidden game mechanic regarding Mega Evolution that effectively causes any potential changes to the order of events in a turn caused by Mega Evolution to nullified. This explains why Prankster works for Mega Sableye after its evolution; it loses Prankster upon its evolution and therefore may move last based on its Speed, but since this is a potential change to the order of events, this change is nullified for that turn. This mechanic works in a variety of situations; Mega Swampert's Swift Swim will not make it any faster on the turn it evolves due to this mechanic.
Even Pokemon that simply experienced a base stat change are affected by this; this is why Mega Beedrill always carries Protect, because it needs a free turn to burn the time it retains its old form's Speed stat due to this hidden mechanic. Similarly, Mega Garchomp could move before a Pokemon that outspeeds it on the turn it evolves if its standard form would have moved first.
To be clear, however, this mechanic does it mean the ability or base stat change wasn't actually assigned to the Pokemon; it simply means that any effect they may have on the order of events is blocked. So if a Pokemon with Trace were to switch into Mega Swampert on the turn it evolves, they would gain Swift Swim even though the ability won't activate on that turn. In addition, all other stat changes and abilities will work as normal; it's only Speed that is affected.
More information