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?

Once you realised that he said bad, immediately ask that person to kindly change the subject. It is not permitted according to quran. If still that person insist and continue speaking bad about other person leave the place.