After doing some brief experimentation, it looks to me as if the attack type actually depends on the attacking unit. The Thor, for example, will always use its ground attack. Here's a table of what attack is used for each unit (I've only listed units that have different ground and air attack):
Unit Attack type
--- Melee units ---
--- Campaign-only units ---
It seems to me that this was designed so that the unit will use its more "powerful attack". The Battlecruiser's ground attack is stronger than its air attack, and the Wraith's air attack is stronger than its ground. My theory breaks down when it comes to the Scout, but I believe this is just a mistake on Blizzard's part, since Scouts can never face off Colossi in the campaign, as far as I can remember.
The Thor is unique here since its attack can be said to be weaker vs ground because of the shorter range, but the ground damage is definitely higher, so I guess that's why it was chosen. On the other hand it may be more complicated than that, as tzenes revealed in his answer.