well, first one has to believe in ghosts or other things that haunt places, because if you don't then the answer is simply: They can't because those things aren't real.
However, if you do believe in these things, then the answer is actually just as simple. Ghosts especially have a tendency to tie themselves to places that had extreme significance to them. This may be where they died, where they worked, or someplace that was an area of strong importance to them. Churches can fulfill all three areas. Add to that the fact that many churches have catacombs, and that many spirits are believed to haunt the place where their physical bodies are buried, and churches are probably one of the most likely places to be haunted.
As for the Spirit of God, I can honestly say I don't know. However, most of the churches that I have heard of being haunted have been either abandoned or simply aren't used for churches anymore. This may be a reason that they became haunted, as the spirits are outraged or upset at the state their resting place has fallen to, and they may even feel that since the place is no longer a house of the Lord then God may have deserted them.
But who know, really? haha