This morning, Joey built a sand castle on the beach, and put a toy flag in the highest tower, but this afternoon the tide  knocked it down. The it is more likely to refer to A sand castle than a toy flag because This morning, Joey built a sand castle on the beach, and put a toy flag in the highest tower, but this afternoon the wind knocked it down.
In "This morning, Joey built a sand castle on the beach, and put a toy flag in the highest tower, but this afternoon the tide  knocked it down. ", The it is more likely to refer to A sand castle than a toy flag because This morning, Joey built a sand castle on the beach, and put a toy flag in the highest tower, but this afternoon the wind knocked it down.
This example is True.