On such occasions, ATC (Air Traffic Control) will ask the pilot to turn the transponder off to reduce confusion.
There are other times, when the aircraft is not flying in controlled airspace, that it's not required to have the transponder on.
And if an aircraft suffers an alternator failure, the pilot may turn off all non-essential electronics to extend the a/c battery life. In those cases, the transponder would be turned off.
ADS-B | TCAS