Targeting is essentially random. In practice what I think happens is ships are targeted in the order in which they entered orbit at the combat location. Targets which have no attacker assigned are selected first. An attempt is made to ensure that all ship/orbital targets are selected before the planet is targeted.