The question derives from oral & written history, and an autobiographical quote attributed to the poet himself:
When I was fifteen, I was fond of sword play, and with that art I challenged quite a few great men.
[Four Seasons of T'ang Poetry, John C.H. Wu]
In the Chinese mythical tradition, this would certainly render him a member of the "Chivalrous Society" of Chinese knight errants (Youxia), similar to Song Jiang. (Song is arguably the least proficient warrior of the 108, but the leader per his superior virtue in the context of the times. Such virtue in Chinese mythology is typically linked to scholarship and knowledge of the Classics, which includes the Book of Songs. Literary style in composition was a factor in Imperial examinations.)
On why it is consistent that he would have carried a sword:
- Li Bai was a wanderer, and roads at the time were dangerous, such that a traveller, particularly one who might, via circumstance, be traveling alone, would require protection.
Li became a Taoist after being banished from the court of Chang An, and the Taoist and martial traditions of China are closely linked back to antiquity, certainly in the classics of literature. [See also: Wudang Mountains, modern works & historical figures such as The Major Methods of Wudang Sword and "Miracle Sword Li", and the extant martial practice, which also includes an active Wudang Temple teaching the Taoist arts.]
Li Bai wrote poems mocking his detractors, such that he might have gotten into situations requiring being able to defend himself.
Li Bai is well known for his love of wine, and drinking tends to loosen one's lips, such that one might be called upon to defend oneself physically.
(Speaking from personal experience there;)
- Li Bai wrote poems of political and social protest, which legend holds he might even have scrawled on the walls of tea houses in fits of fervor, requiring subsequent quick exits from town in the dead of night.
Li Bai was said to have served as staff advisor to Prince Yong in the civil war in the mid 8th century, which would have included battlefield situations. (Note that Socrates participated in combat in the Peloponnesian War, a not uncommon circumstance for people in ancient times.)
The expression "Three wonders" of the Tang era denotes "Li Bai's poetry, Pei Min's swordplay, and Zhang Xu's calligraphy". As Li was acknowledged as skilled in calligraphy, it's not a stretch to presume he was also a skilled swordsman, all three endeavors being high art forms in Chinese culture.
Since history is unreliable, perhaps a better question would be "why might Li Bai have carried a sword?"