There are some situations where when conversing with a person, they unexpectedly say something bad about another person and we have no clue to anticipate that this person will actually do ghibat. What can we do in this situation? Is it still ghibat although it was beyond our control?

You should still take the opportunity take the opportunity to advise the person not to talk ill of others during their absence. This should be done respectfully and diplomatically.