Chapter four of William Golding's Lord of the Flies is titled "Painted Faces and Long Hair," and the long hair part of the title indicates that some time has passed. The painted faces aspect of the title refers to Jack's literal face-painting at the end of the chapter, of course, but it also indicates a more noticeable move from civility to savagery by the boys on the island.
The littluns, including Henry, have built an intricate and expansive sand castle, complete with complex railway lines and ornamentation, and Golding says the younger boys enjoy playing here. When Roger and Maurice appear, they have just been dismissed from signal fire duty and are simply going to the beach for a swim. They have no evil intentions and no particular motive for what they do next.
Roger led the way straight through the castles, kicking them over, burying the flowers, scattering the chosen stones. Maurice followed, laughing, and added to the destruction.
Clearly there was no specific motivation for these two older boys to destroy the sand castles as they walked by; what is noteworthy about the incident, however, is what happens afterward. Two of the boys just keep on playing, because the part which was destroyed was not the part they were playing with, indicating that in some ways violence and destruction are now acceptable occurrences on the island. The remaining boy, Maurice, gets a little sand in his eye during the fracas and Maurice hurries off. Golding explains it this way:
In his other life [his more civilized life before the island], Maurice had received chastisement for filling a younger eye with sand, Now, though there was no parent to let fall a heavy hand [punish him], Maurice still felt the unease of wrongdoing.
Maurice mumbles an excuse and heads off to go swimming.
The significance of this is that there is still something holding at least some of the older boys back from complete savagery. While there are no actual adults on the island to help maintain civility, their authoritative presence is still felt and serves as a restraint (or at least a sense of guilt) for hurtful activities. This is reinforced by the next story of Roger throwing stones at Henry. While he is throwing stones, which is not a socially acceptable activity, he does avoid getting too close to the boy.
Here, invisible yet strong, was the taboo of the old life. Round the squatting child was the protection of parents and school and policemen and the law. Roger’s arm was conditioned by a civilization that knew nothing of him and was in ruins.
The answer to your question is simple: the older boys ruin the sand castles because they are older boys and that is just something some older boys do; it is the reactions and responses to this act which deserve the most attention in this episode. These episodes are indications that, in chapter four, there is still some restraint on harmful acts among the older boys but the younger boys are already rather accepting of violence perpetrated than the older boys.