From Professor Trelawney and her prophecy to Regulus Black and his discovery of Voldemort's plans for Slytherin's locket, these characters were all part of Harry Potter's overarching story.
Dumbledore also knew about the prophecy that Professor Trelawney foretold long before Harry ever came to Hogwarts. He knew that in order to kill Voldemort, Harry likely had to die as well.