Ghosting is basically the game attempting to figure out if a player is trying to ruin the game for others. An extreme example of this would be if someone were to get pissed or just simply decide to be a dick during a race and start driving in the opposite direction on a track with the intention of causing a head on collision. The game will notice this and the cars driving properly will just pass through the car driving in the opposite direction. Another example would be if someone were taking a corner too slowly with another car approach quickly, the game may read that and decide to ghost that slower car.
It's really just a way to try to make online races more enjoyable by taking out a common issue of players who want to ruin the experience. But since it's not a perfect, you also have that built in grading system that will reward or punish you for how you drive