When playing XvT, Terran's often employ a barrack's or a factory as a cheap scout. I've also seen a lot of cases where they will like to fly the scout over one part of your base (say your main base) while then flanking with their army and attacking your natural. The reason for this is that often the opponent will overreact when they see the scout and draw too much of their army away leaving their natural exposed.
Recently though, I played a Terran who flew a factory overhead right before we engaged in battle, and several of my stalkers were attacking the factory instead of the opposing army.
Are there other ways to deal with this than just trying to micro each individual unit to not attack the flying building? Why is the building attack priority not tuned such that this would not happen?
This applies in a similar sense to Zerg's who bring in many overlords when attacking to absorb fire as well.