I know Cao Cao and other warlords have their own ambitions, but since Liu Bei had the legitimacy, why didn't they recognize him as the next Han emperor? Did anyone even know at that time?
I'm afraid I wasn't 100% sure of the exact question being asked, my apologies, so I have tried to cover the bases with this answer.
The short answer: Liu Bei didn't have the legitimacy, he was just another Liu figure among many others including warlords. There was already an established Emperor, a puppet perhaps but one that it would be hard to justify overthrowing. For all sides, recognizing a rebel Emperor would be destroying their claims to legitimacy and for Liu Bei, it would have been an incredibly risky move.
Liu Bei's Claim To The Throne
So the novel makes a huge thing of Liu Bei's lineage throughout his life. Mothers like Xu Shu's or Lady Wu speak in awe of this member of the imperial clan, other members of the Liu clan rush to proclaim their ties, even in the first chapter when Liu Bei has not yet fought a battle Liu Yan treats Liu Bei with the esteem of a relation. To put the matter beyond all doubt, Emperor Xian has the matter looked into and declares Liu Bei an Imperial Uncle, a title used a fair few times by others about him, all Liu warlords love him. Historically, Liu Bei's lineage was not such a thing of wonder and only begins to become of clear use to him on the national stage in the early 200s.
By the time the civil war that led to the three kingdoms had started, there had been over twenty Han Emperors, a usurpation (with a new dynasty) and civil war. That civil war resulted in a change from Liu Bang's line to Liu Xiu's in a continuation of the Han but also a distinct break with a new capital and willingness to contrast itself with the Han that had come before. There had been many generations, many children begot more children (Liu Sheng, the son of Emperor Jing and Liu Bei's ancestor had 120 children) and other Liu warlords were also from Emperor Jing's line. There were a lot of Liu's about. Liu Bei's particularly line was perhaps not without some local clout, able to get provincial posts and connected enough for a distant family member to pay for a good education for Liu Bei, but they no longer even had the rank of marquis as status (losing it as far back as 112 BCE) and had no clout at the capital. Liu Bei was of the Han line but a distant relative, not in normal contention for the throne.
During Liu Bei's life, there would be four Later Han Emperors before Emperor Xian's abdication that saw Liu Bei claim the throne himself. When Emperor Huan died without an heir (a practice the Later Han was all too used to) on 25th January 168 CE. The outstanding successor candidate King of Bohai Liu Kui, the younger brother of the Emperor with seventy children, had been accused of treason and though pardoned on Emperor Huan's deathbed, he was out of the running (and would be killed on false charges in 172). The way to find an heir was well practised and known, the Dowager Dou would pick in this case with the consultation of family and trusted officials. Liu Hong, the future Emperor Ling, was not the closest candidate by any means but he was old enough for infant mortality to not be a huge issue and young enough that the Dowager and her clan would have a chance to rule, he was of Emperor Huan's family line and his claim to lineage (marquis though a poor one, great-grandson of a King and descended of a Later Han Emperor, not a Former Han Emperor) was still far stronger than Liu Bei's.
When Emperor Ling died on 13th May 189, he had managed to have two sons though he failed to properly secure the succession in favour of the son he wanted. The Dowager He and her family installed the eldest son (who was also her son), there was no need to go searching for another relative and confuse the matter when one of clear lineage was right there. However, the split of the He family would turn fatal and tensions between the gentry and the eunuchs exploded in fire, massacre and looting. When the general Dong Zhuo stepped into the chaos, he moved quickly to seize control. On the 28th of September, Bian's short reign ended as Dong Zhuo forced Bian's mother to depose him for supposed lack of virtue and ability. The replacement? Dong Zhuo didn't need to search for one, there was a younger brother Liu Xie, who quickly became Emperor Xian, who was too young to be a threat or hold power and whom Dong Zhuo claimed distant kinsman links via Xiu's grandmother and claimed was the superior talent and figure of virtue of the two brothers. On 22nd March 190, Liu Bian would be forced to take poison and did so bravely in a sad moment with his concubines.
Liu Bei had no stronger claim than these candidates for him to be proclaimed Emperor during any of those times. The poor records of Shu-Han mean, as Pei Songzhi bemoans while noting that the gap between Liu Bei and Emperor Jing was now extremely distant (over three centuries by that point) it is now unclear what family precedent he used in the ancestral temple he established as Emperor.
We only first see Liu Bei being connected with the imperial clan in wider decisions and discussions when he meets with Zhuge Liang, it begins to come into play in diplomatic terms when Zhuge Liang argues the case for Sun Quan to ally with Liu Bei against Cao Cao when having to justify Liu Bei's resistance. Before then, there were a ton of Liu relatives around the land (one of Liu Bei's earliest followers Liu Yan was also of the Han line), and Liu Bei's main assets were his reputation among the populace, the loyalty of his men and his military skills. Only late on did his Han lineage becomes a notably useful political asset, to help justify his fight against Cao Cao. Then the diplomatic moves around Liu Zhang but there was more about their being kin rather than about Han lineage. Then after his conquest of Hanzhong to draws upon the past while still claiming loyalty to Emperor Xian.
This didn't mean that people weren't aware of Liu Bei's background but this was just a detail for much of his life, a fun little fact that perhaps some of his officers enjoyed. With so many other Liu's around, his claim so distant and so many other political practicalities when dealing with Liu Bei, the idea that he was the Han Emperor to be was probably not foremost in the mind of his rivals and allies.
As A Potential Alternative To Emperor Xian
There isn't a big dispute in the texts about the lineage of Liu Bei or his son Liu Shan, the Wei historian Yu Huan only goes as far as to suggest Liu Bei was descended from a different son to Liu Jing than the one claimed. None of the rivals seems to have targeted Liu Bei's lineage as something questionable they could pick at.
So one problem with "recognizing Liu Bei's legitimacy" was, that there was already a Han Emperor during the civil war until the abdication after Cao Cao's death. Had Emperor Xian died, depending on the timing, the natural choice would have been one of his sons: Feng died early, two were killed by Cao Cao, one with an unknown name who died before his father while Xi, Yi, Dun and Miao were alive when Emperor Xian abdicated. Had he died before having kids/they all died at once due to plague, fire or the edge of a pointy thing then a controller (who might be facing a rather big scandal) would likely have continued the established precedent. Someone from a closer line (a King or a Marquis) who just happened to be old enough not to die within five minutes but young enough to need a regent and be controlled for some time. Though the Sima's would later prefer older and pliant candidates for the role of Wei puppet Emperor, particularly when trying to get around the wily Dowager Guo, so that was also a potential card.
Even in a scenario where the controller had to pick a warlord Liu to become the Son of Heaven, there were various options out there. Liu Chong the crossbow expert and King of Chen. Liu Yu the popular Governor of You (his son He was not a warlord) had a distant claim via descent from the founder of Later Han. Emperor Jing's descendants had a few powerful warlords among them: Liu Biao (and his sons) the scholar Governor of Jing, the ambitious Liu Yan and his weak son Zhang of Yi. The brothers Liu Yao of Yang and Liu Dai of Yan also claimed Han lineage. So why would any such controller pick Liu Bei of the options?
It wasn't unheard of to try to replace the sitting Emperor but it was problematic. Dong Zhuo did it and while his attacks on Liu Bian seem to have stuck in the centuries since, the move to replace the Emperor didn't help central authority or the new regime. In the coalition that rose against the new controller, there was a discussion about replacing the young Emperor. Yuan Shao as head of the coalition and his boss+supply master Han Fu of Ji claimed Emperor Xian wasn't the real son of Emperor Ling, that he lacked virtue, signs from heaven, suggesting the well respected Liu Yu became Emperor. The leader of the coalition's southern forces Yuan Shu objected as would create more chaos, Dong Zhuo rather than the young Emperor were to blame for the troubles including the massacre of their family. Cao Cao also objected on similar grounds of no grounds to change Emperor and would create confusion to have two Emperors. Perhaps more importantly Liu Yu rejected this as treason and would similarly reject attempts to set up a government in exile with him as its administrative head.
1/