The amount of squares the building takes, and how good the building is.
Like a 10 mins booster is basic, and an 20 hours is legendary, it is the same.
Based on the number of tiles the building will take, its subtype changes (and gives you more fragments upon disenchanting.)
Also, how good the building also influences, as there are many 3x3 rare or epic ones, but the wells, 3x3 are legendary, for example. Or the mysterious egg, it's only a 2x3, and it gives a decent culture, and mana, therefore, labeled as legendary. That awful Tower of Fire, 2x3 also is labeled as basic, because of its junk. (And sadly, I have four of them as I had to move the chicken, from 5% chests!! haha) I can't stop getting the exclusives, even if I do not want them haha.