Why do terran players float buildings with their armies? Does the computer automatically target buildings?
There's a couple of advantages to having a floating building with your army.
Generally, any building that is being floated (by a good player, anyway) would otherwise have been idling - Barracks after switching to a mech army, for instance, or command center without a mineral patch to land at.
There may be other reasons, but those are the biggest, I think.
Raven Dreamer has listed two great reasons for floating buildings. There's another more nuanced reason that experienced Terran players use.
There's a detail about the Seige Tank that makes floating buildings very useful.
This means that a seige tank can actually hit farther than it can provide vision for. So if a seige tank is in the front line of the army, then it's effective attack range in seige mode is 11. But if a player floats a building in front of the tank and provides that extra 2 range, then the player can take advantage of the seige tank's full attack range.
This is critical in TvT. Imagine a Red Terran and a Blue Terran. The Blue Terran has a tank line right outside the Red Terran's natural expansion, but is not giving his or her tank extra sight. How can the Red Terran push out with his or her own tanks?
Red can float a barracks over Blue's tanks, giving Red's tanks extra sight. Then Red seiges up 12 or 13 range away and can shell the Blue tanks freely without any return fire. (In Brood War, an attacking unit would reveal itself from fog of war, so the Blue tanks would actually fire back, but with a delay.)
There's actually a nice video on this. The Red player is providing vision with Vikings.
You can also do this by scanning, dropping mules, running up a cheaper unit (marine, hellion) or sighting with a flying unit (usually medivac). But if the building's not being used, then it's a great tool because a barracks costs no gas, less minerals loss than a scan, has no energy limitation and is hard to harass because it has 1000 hp.