What happens if a Ditto in a Gym (as the first Pokémon of said Gym) faces a Ditto which a Trainer sends out first?
From this GamePress article:
When one Ditto faints or switch out, the winner transforms into its next opponent.
Also from this page, the video linked in the article directly under "Battling with Ditto" shows that there is no recoil damage for using the move Struggle, contrary to the main series mechanics.
As for having a Ditto transform into a transformed Ditto, according to this compilation of Ditto mechanics:
Ditto can not use Transform on a Transformed Ditto
Additionally, from this article, it appears that attempting to switch a Ditto back in to battle results in your Ditto fainting:
The player used Ditto first up against the gyms defending Ditto but didn’t make much damage at all, so he/she decided to switch with Jolteon which then caused the gyms Ditto to transform however once the gyms Ditto was defeated, the trainer attempted to switch back to his/her Ditto but it was listed as fainted.
This happened despite barely taking any damage at all from the short battle with the rival Ditto.