Is there anywhere I can read a more detailed description of the earthquake bug?
There is a more detailed description in the Physics section.
Did I understand correctly that the bug works when there is no castle, and it always kills the topmost stack of the enemy (or your own, when the defender casts it)?
It kills the very first stack in the unit, and yes, it can also kill your own stack. Also, it seems like you can kill the second stack if the first one has already died naturally, but I haven't tried doing that.