why don't they loose their immunity like when using roost, gravity, etc. (after all, they are IN the ground)? Just wondering if there was actually a justification for this phenomenon?
Its full body wont be touching the ground only its body part which used for digging will touching the ground. In other words,it will be flying/levitating in the ground and at the same time it will be digging.
If your doubt is for a game working question it's because the ability levitate and the flying type give straight of inmunity to ground type attacks such as earthquake, there must be some kind of order in which this calculations or effects are taking in count and the ability must be on of the first or last.
Now, if your looking for a more physical or real life answer there can't be such, remember it's just a game (probably aimed for kids PROBABLY) and that there's much other questions like this that can't be answered there for gamefreak or the game it self does not offer a realistic biological explanantion of what happens in game.
It dosent work for dig oddly, but gravity and roost actually DO act like that, they make ground hit levitate/flying pokes. EDIT:didnt notice you said like before the others, it just dosent hit them, thats it.
my guess would be that earthquake just shakes a large section of earth without breaking it apart and flying type mons would able to fly through the tunnel that they dig using telekinetic powers without touching the shaking ground so they can dig without actually coming into contact with the ground but strictly speaking this would only apply to flying psychic types unless we assume that mons have special powers to do their moves