Basically because caffeine is not classed as an intoxicant.
SeekersHub explains this as:
So what is meant by intoxicant in this context is that which “covers the intellect,” i.e., causes inebriation or drunkenness like beer, or euphoria such as cocaine or amphetamines. These are all unlawful. ... Caffeine is not an intoxicant in that sense, but rather only a mild stimulant and hence permissible.
quoting the hadith
... [Khamr] is that which clouds the intellect ... -- Sahih Muslim 3032 a (sunnah.com)
This is consistent with fatawa by Islam Q&A (1; 2), IslamWeb, and IslamToday.
A BBC article discusses this history of a fatwa declaring coffee haram:
Coffee drinking was banned by jurists and scholars meeting in Mecca in 1511. The opposition was led by the Meccan governor Khair Beg, who was afraid that coffee would foster opposition to his rule by bringing men together and allowing them to discuss his failings. Thus was born coffee’s association with sedition and revolution. It was decreed sinful (haraam), but the controversy over whether it was intoxicating or not raged on over the next 13 years until the ban was finally rescinded in 1524 by an order of the Ottoman Turkish Sultan Selim I, with Grand Mufti Mehmet Ebussuud el-İmadi issuing a fatwa allowing coffee to be drunk again. Beg was executed for his troubles by command of the Sultan himself, who further proclaimed coffee to be sacred. In Cairo there was a similar ban in 1532; coffee houses and coffee warehouses there were ransacked.