how does the game determine whether an item can be traded or not?
If the item drops while you're in CoF, but it has no CoF requirement, it has an untradeable variable set to true, and this is reflected on the tooltip. You can still use that item if you switch to MG, and any MG party members you gift it to can equip it, but it cannot be sold.
Items can be traded if they drop while you're in MG or when you're not in any faction.
I thought if you side with MG, items only become marked after you buy something from the bazaar, wouldn't that mean all items would drop without a faction requirement?
That's correct. Items you find while in MG have no faction requirement, just like items you find while not in a faction. It's only buying an item through the Bazaar (edit: including via a direct player to player trade) that gives it an MG requirement.