Caledorn
Emperor
I think it is not at all something to be frowned upon. There are many reasons for this. But as the main reason for city gifting to be banned is to prevent "gift-upgrade-gift back" cycles or "gift-city-repulse-enemy-gift back" tricks or "gift city to prevent capture" or "gift city to keep a nation alive" or "gift city, steal tech, gift back" and so on, I think this "workaround" with leaving a city empty is nothing to be worried about as it have nothing to do with those few scenarios.
Even more, we might not at all take the city from the barbs, but just kill all defenders but one and invite SpAp to come and take it.
Well, I am not willing to risk being accused of being rule breakers over an assumption - possibly even tainting our potential future victory with "Oh sure, CFC won, but they did it by interpreting the rules in the widest sense possible when they felt it was to their benefit". So if we capture the city and then intentionally allow SpAp to declare war upon us so they can capture the city, and then proceed to negotiate peace with them again after they have captured it, let it be known that I am strongly opposed to the idea just for the record.
I have no objection to the second scenario you describe though, as it is only natural that an ally helps another.