Frank Herbert's Dune book begins with a sentence that describes Castle Caladan as a pile of stone that has been home to 26 generations of Atreides Dukes. Not being a native English speaker, I am left to wonder as of what does it mean. Does the word "pile" here really mean that the castle was actually a ruin?
I don't believe we're meant to think the castle is in ruins. "Pile of stone" here is serving as both a literal description — anything made of stone can be described as a pile of stone, it's just that some piles are more, um, ordered than others — and as a put-down of stone castles and the social class that lives in them.
Pile can also mean castle.
As you say, given the commonest modern meaning of pile, Herbert’s phrase evokes the image of something haphazard, maybe even ruined.
But pile also has an older meaning, given by the OED as “A stronghold, a castle, esp. a small castle or tower […] Now arch. and rare.” Though rare, it’s still used in a few well-known phrases — most notably “ancestral pile” — enough so that I’m pretty sure Herbert had this meaning primarily in mind.
However, heap has been the primary meaning for long enough that I suspect all modern use of the castle sense has become somewhat coloured by connotations of haphazardness, disorder, etc.; certainly it’s generally used for slightly humorous effect. (I seem to recall PG Wodehouse being quite keen on the phrase, though I can’t remember any specific examples.)