This is specifically a Spelunky 2 theory; I don't think it applies to the first two games. Also may include serious spoilers.
Now, I came up with a theory as to why the Ghost attacks you, lore-wise.
Firstly, let's take Eggplant World into account. The Ghost doesn't "spawn" there, because she's already there, floating above her own grave as evidenced by the Camera!
Given that Eggplant World is pretty much a safe zone if you don't manage to SD via throwables or whatever, I think the Ghost is actually trying to SAVE the Spelunker's soul by somehow guiding it to Eggplant World instead of killing them just for kicks, and the process is simply easier if she disposes of the Spelunker's body, hence why you gib when you're caught by her.
Magmars might provide some extra evidence; the Journal states that they may be the trapped souls of past spelunkers who've died in lava.
I'm not entirely sure how to tie Curse Pots into this theory, but maybe it simply alerts her to the location of whoever broke it, and the usual three minutes consist of her blindly searching for the Spelunker.
In short, the Ghost killing you is a misguided attempt at leading the player to the one safe place in the Caves, so that their soul doesn't become trapped in the worse areas.
What do you guys think?