Stepts to reproduce:
1) Place a non-standard quality building when you only have 1 of them in your inventory
2) Use pipette tool (q) to get a ghost copy of the same quality building in your cursor.
3) Place a ghost.
So long as you have ANY QUALITY of that building in your inventory, it'll place the same quality as the ghost. E.g. if you place a ghost of a legendary turret and have only standard turrets in your inventory, it'll spontaneously change one your standard turrets into a legendary one.
Haven't actually tested with non-standard quality items, so unsure if it'll downgrade, but upgrading standard to any quality is a pretty huge exploit.