There's a ReplacementBuildingClass column in the Buildings table. No Building uses it in the base game, so it may not be hooked up, and I'm not sure if it refers to the BuildingClass that's being replaced or doing the replacing. I assume you added a new BUILDINGCLASS_BAZAAR that you can put in that field for the BUILDING_MARKET row (or try putting BUILDINGCLASS_MARKET in the BUILDING_BAZAAR row).
If that doesn't work, you'd have to use Lua.
ReplacementBuildingClass is not used anywhere in the stock/vanilla game files, but I can say for certain that it is hooked up, and does indeed work -- I am using it in my mod currently.
The only issue is that there does exist a couple quirks about how it works.
ReplacementBuildingClass must be attached to the
source building, as it defines
which building class replaces the current building.
Unfortunately, this means that in order to replace a Market, you would need to either edit/update the Market entry globally, or create a unique Market copy for a particular Civ so that you can attach the column to it.
On the specifics of how it works, it only really does half of what you think it would do.
Upon the discovery of the technology which unlocks the replacement building, all existing instances of the to-be-replaced building are
not swapped for this new building -- they stay!
However, all
currently-under-production* are swapped over to the new building
with their construction progress intact, and the old building will no longer show up as available to build.
* There is a caveat with this swapping - it seems the game internally might only look at this along the lines of PlayerDoTurn or something similar, as this "swap" is delayed by one turn in my testing. What this means is that if an "old" building is constructed on the
same turn that the "new" building is unlocked by research, the game fails to swap it in time. If there is at least 1 turn remaining on construction,
so long as the user does not attempt to reassign construction the building will be swapped, and progress (hammers invested) preserved.
If at any point the user reassigns construction manually to the new building, all hammers will be lost.
There exists a secondary caveat!
If the building requires a strategic resource to build, and the Empire no longer has any more available,
all versions of the building will appear although they will be unbuildable due to lack of a resource. It appears to be a flaw with the logic the game uses to display buildings which have no available resource -- normally invisible since the game does not replace any buildings!
But as a specific example, if the Market and Bazaar both required Horses, once available Horses were exhausted, both the Market and Bazaar would show up in the city build list, but greyed out, citing lack of horses. Once Horses are acquired, the Market disappears again.
What does all this mean?
Unfortunately, if you want to do upgradeable buildings, you will still need some Lua to actually replace the buildings manually.
I've done this in my Civ/mod, except I have a chain of 3 upgradeable buildings, and I had to resort to a combination of ReplacementBuildingClass and some Lua to get everything working cleanly and seamlessly.
WARNING
There is yet another side effect of using ReplacementBuildingClass -- whatever building you replace will no longer be eligible for construction, as stated above.
However, for buildings which are a
prerequisite for another building, such as Shrines and Markets, the replacement building
will not count as a valid prerequisite! This can mean that a replaced Shrine will not allow you to build a regular Shrine anymore, and thus block you from ever building a Temple.
You cannot give it a building from the same building class either, as the column is called
ReplacementBuildingClass, and the game will refuse to recognize it if it was not specified as a UB for a specific Civ.
(Ask me how many issues I've run into now to know about this...)
I was going to point you to LeeS' advanced building guide here, but upon a quick glace, it appears he does not have a section on this column available yet. I've worked with him already to work out these specifics, but I imagine he hasn't had time to update his guide.
In short, yes, OP, it is possible to do -- I do it with my mod, with a more complicated chain of 3 replacement buildings, but the same logic applies.
Your best bet is to update the Market to have ReplacementBuildingClass pointing to your new Bazaar.
This will take care of hiding the building, as well as allowing the ability to preserve hammers spent building the Market when the Bazaars get unlocked.
In Lua, you will need to come up with a function to actually replace said building, using SetNumRealBuilding(). You'll also need to plan around any buildings which rely on the Market being present (East India Company, I believe.)