How to make only obstacles slip through like a ghost?

Sorry. Problem solved.

Set collision on the object to block both ghosts and players, and make the object block only the player.

After that, when the ghost enters a state where it is chasing the player, disable collision, and enable collision after it loses sight of the player.