Can a wizard fabricate stairs out of a castle wall?
Short Answer?
Yes, but it's really not worth it.
Long Answer?
I have to lead off by pointing to KRyans answer regarding what constitutes as "Raw Material" in Can coins count as raw materials for Fabricate?
Example 1: You can make bricks into a 5ft wall, but you can't make bricks into a pot.
Example 2: A raw egg is viable Raw Material to make a Hard Boiled Egg or a Scrambled Egg, but if I crack it out of the shell, I can no longer make it into a Hard Boiled Egg, even if the egg is still raw.
It's really all about context.
"To build a brick building, would newly crafted unused bricks be a raw material or river bed clay?"
As per the rules of the Fabricate spell: (PHB 239)
If you are working with metal, stone, or another mineral substance,
however, the fabricated object can be no larger than Medium (contained
within a single 5-foot cube).
Bricks: Valid. Dry-stacking is a documented construction method.
Clay: Even Better. On top of making bricks to whatever specification you want, clay mortar was also commonly used in the medieval era.
However,as both materials are mineral substances you would be limited to building within one 5 foot cube at a time, costing 10 minutes and at minimum a 4th level spell slot each time.
"If bricks can be used, could a wizard use a broken house as material to build a new building?"
(emphasis mine)
- No. Well, kind of. A wall isn't really raw materials. You'd have to salvage the bricks out of it first.
- See previous point about size limitations for mineral substances.
You may find yourself asking: "But what if the broken house was made of wood?"
To that I say: Get out of here we're clearly talking about bricks.
But since you asked so nicely, it depends on how much of the wood is salvageable because as per the spell description:
The quality of objects made by the spell is commensurate with the
quality of the raw materials.
If this hypothetical broken wooden house had been burned down or smashed to splinters, then that is not a viable construction material for making a new building. Any broken lumber would have to be salvaged first before being used in the spell the same way that it would be used if you were to do this without the spell. This is supported by the requirement for tool proficiency to fabricate things requiring a high degree of craftsmanship, such as building within the increased limitations of reclaimed lumber.
"Could the wizard use an intact building for materials for his tower?"
- Kind of. See above regarding salvaging materials.
"Finally, could a wizard turn someone's fortifications into a staircase leading right to them?"
- Kind of. See above regarding salvaging materials.
But bear in mind that even after breaking down the stone fortifications of a castle for raw materials, it would take you 10 minutes and a 4th level spell slot for every 5 feet of stairs you made. Meanwhile, anybody that noticed could try and counterspell you every 6 seconds.
Furthermore, a staircase "right to someone" is a bit subjective. If you spend an hour casting spells the "someone" in question could just leave.
You'd be better off Fabricating a wooden ladder.