child is learning shapes and is training fine motor skills.
building with blocks also develops the ability to concentrate longer, be patient if details fall and child needs to start over again. it also teaches not to give up and achieve your goals.
building castles child learns how to create order form chaos, a unit out of a pile of elements.
creating constructions is the first acquaintance with causal relationships - child tries out hypotheses and sees whether they work or not: will my castle hold on on 3 cubes or will it fall? how many cubes can i stack on each other before the tower falls?
building something out of imagination is quite hard - you need to develop this skill, this way kids learn 3-dimensional thinking and try themselves as architects or designers.