There are three types of buildings:
Core Buildings (Shop > Core)
Resource Buildings (Shop > Resources)
Defense Buildings (Shop > Defenses)

Only Defense Buildings and Resource Buildings can be demolished with 'Powder Keg' or 'Hammer'. When a building is demolished, you will get the building space back and use it to construct another SAME type of buildings.

The Core buildings cannot be demolished.