We know because we can check a bunch of what he wrote. Not everything - not the miracles, not the resurrection - but we can check a bunch of the background details against known secular history.
When Luke wants to locate the start of John the Baptist's ministry in time, he says, "In the fifteenth year of the reign of Tiberius Caesar, Pontius Pilate being governor of Judea, and Herod being tetrarch of Galilee, and his brother Philip tetrarch of the region of Ituraea and Trachonitis, and Lysanias tetrarch of Abilene, during the high priesthood of Annas and Caiaphas, the word of God came to John the son of Zechariah in the wilderness." We can check that all those people were in those positions at the time Luke said they were. He's tying the events he's narrating to a specific, concrete historical setting.
One little thing that I notice: When he's writing Acts, Luke is at times part of the events. He's describing Paul's travels, but sometimes it's "he", and sometimes it's "we" - that is, Luke is traveling with Paul. And whenever it's "we", the level of detail goes up. The ship had this figurehead. Here's where we sailed, day by day. But when Luke's not part of the party, he doesn't know at that level of detail, and he doesn't say what he doesn't know. That's a careful writer.
When Luke wants to locate the start of John the Baptist's ministry in time, he says, "In the fifteenth year of the reign of Tiberius Caesar, Pontius Pilate being governor of Judea, and Herod being tetrarch of Galilee, and his brother Philip tetrarch of the region of Ituraea and Trachonitis, and Lysanias tetrarch of Abilene, during the high priesthood of Annas and Caiaphas, the word of God came to John the son of Zechariah in the wilderness." We can check that all those people were in those positions at the time Luke said they were. He's tying the events he's narrating to a specific, concrete historical setting.
One little thing that I notice: When he's writing Acts, Luke is at times part of the events. He's describing Paul's travels, but sometimes it's "he", and sometimes it's "we" - that is, Luke is traveling with Paul. And whenever it's "we", the level of detail goes up. The ship had this figurehead. Here's where we sailed, day by day. But when Luke's not part of the party, he doesn't know at that level of detail, and he doesn't say what he doesn't know. That's a careful writer.