Nancy Pelosi is only the most recent in a long line of US congressmen and women to visit Taipei. A predecessor, Newt Gingrich, famously went in the 1990s. It's a regular port of call for congressmen and women visiting the Asia-Pacific and Australia. US senators visited in June 2021 and again in May this year.
Pelosi is part of a very large, probably majority, Congressional group that supports Taiwan, wants to see it defended at all costs, and views China's claims over the democratic state as fundamentally illegitimate -- at odds with the view of successive US administrations that support a one-China policy and the retention of the status quo in regard to Taiwan.
It's a long-standing tension, and not confined to Taiwan or China. Congress is often more hawkish than presidential administrations are -- even when of the same party. Even Ronald Reagan was seen as too soft by Republicans on the Soviet Union when he was negotiating with Mikhail Gorbachev on nuclear missile reductions.