I'm not opposed to having some early buildings in lines obsolete.
Buildings obsolete when the next building in line is available (e.g. Walls obsolete at Chivalry).
Obsoleted buildings
1. cannot be built;
2. are still effective;
3. are immediately destroyed when the upgraded version is built.
Upgraded buildings retain all stats and abilities of the obsoleted buildings.
So Castle would have +1 city strike range, +14 CS, +125 HP, +2 flat damage reduction, +20% supply from population, -10% empire size modifier, +1

on quarry, +1 art slot.
This also further lowers building maintenance late game.
I disagree with destroying the obsolete building when the upgrade is built.
1. If the upgrade gets the stats and abilities of the old building, there's no reason to build the old building if you're near the tech for the new one. It's just a waste of hammers. If city A has walls and city B does not, once they build a castle the benefit of building the walls disappears.
2. Rather than helping city specialization, this would tend to make all cities the same. City A and B now both have a castle and no walls.
3. In real life, we don't demolish the university to build a public school. We don't demolish the hospital to build a medical lab. Old buildings remain while new ones are added. A city can have an old historic castle or market and
also have a military base or a bank.
4. Buffing the stats of every later stage and demolishing the early buildings would give the same yields as leaving the stats as they are and letting old buildings remain. The latter requires much less effort.
5. If maintenance costs of too many old buildings becomes a problem (I don't think that's likely in practice, considering old buildings cost much less than modern ones), it's always possible for the player to choose to destroy them and sacrifice the yields/effects.
The way I see it, City A with walls and a castle is better than city B with just a castle, but city B can use those hammers to build other stuff, then build the castle relatively quickly because it doesn't need to build a completely different building first.
As far as founding cities later in the game, I think the behavior of pioneers and colonists would have to change. It is kind of funny that in the 1800s, some colonists would build a new city with... an ancient shrine and monument, an amphitheater, etc. Perhaps if pioneers and colonists just gave a bunch of food and production when used, that could support the cities while they build up some infrastructure. If they start with more population, there's a risk they could starve if the food buildings don't get built fast enough. Maybe they could start at 1 pop and a bunch of food in storage to be used to grow as the player sees fit?
Aside from the pioneer/colonist changes, the changes for buildings would be as follows:
- remove requirements to build the previous building in a line
- make buildings unbuildable when the next building in a line unlocks (at this point, the only link between buildings in a line would be the way they obsolete, and their similarities in function)
- remove all required buildings from national wonders (or don't! Maybe it's okay if they can be missed, or not be valid options in every city! They would likely warrant tweaking at the very least)
- adjust policies, beliefs, and tenets which reference specific buildings.
I think the result of this would be that every city has a different mix of buildings based on its priorities, and that every city would have
fewer buildings overall, which would require some balancing to make feel right. But I think it would be a good direction to experiment with.