Issue:
Fighting against NPCs, if I and the enemy have 2 Pokemon left and I use Destiny Bond on Mega Banette to take down the second last enemy and he defeats Banette, thus gets defeated aswell and Ditto is automatically sent out due to it being the last Pokemon, it will turn into the Pokemon defeated by Destiny Bond instead of the new one coming in.
This seems to only happen when Ditto is your actual last Pokemon, but I can't confirm this. It may be that it also transforms into the wrong Pokemon if you used Destiny Bond and it's not the last Pokemon in your party, but you chose to send it in.
Theory:
A similar scenario I could imagine to have a problem like this would be e.g. taking out the second last Pokemon with a move like Flare Blitz and you are defeated due to recoil, then Ditto gets send in.
Example in detail:
Mega Banette vs Blaziken
Mega Banette uses Destiny Bond
Blaziken defeats Mega Banette
Mega Banette faints
Blaziken faints due to Destiny Bond
Ditto is automatically sent out as last Pokemon
Ditto transforms into Blaziken
Enemy sends out Groudon