We know Bran is the three-eyed raven, meaning he has the power to see events in the past and present. He can also warg and is touched by the Night King in one of his green sights, both of which are components to the theory, but not the focus. With all that power, he goes back in time to whisper to Aegon Targaryen, telling him to set fire to the White Walkers. That doesn't work, so he goes back again and builds the wall as Bran the Builder (casually establishing Winterfell and House Stark). Then, he goes back even farther, to the creation of the Night King. That time, he is stabbed in the heart by Dragonglass and becomes the Night King.