The sentence could have been written as: Ally saw the castle and pointed at the castle. This has the noun phrase the castle in twice. To avoid this repetition, the pronoun it replaces the noun phrase the castle.