Oh man, where to begin. The decline of forums isn't due to one factor, but it's due to a combination of mutually-reinforcing factors:
1) Losing users to social media. Forums were a place to meet people and socialize, now twitter/facebook/instagram fill that niche and do it more expertly.
2) Losing users to chat apps. Forums were a social space for friends once upon a time, now whatsapp/snapchat/discord are where people talk to friends.
3) Aging GUIs. Most forums have outdated GUIs which improperly scale to modern displays. They're either too compact (for an 1024*768 era), or they made a failed attempt at modernization and it looks terrible.
4) Consolidation of forum hosting. Tapatalk bought every popular free forum hosting provider (such as invision) and forced everyone to create a new "tapatalk" account to continue using the existing forums. Then they forced everyone to convert their forum to a new GUI (which was questionable at best). They pestered forum owners to pay up. They pestered forum owners to beg their community for money by adding a donation badge.
5) VPS providers suck now. AWS has drunk their milkshake, they're fighting over scraps that fall from the table. (For those who don't know, VPS means a cloud provider that typically provides a managed PHP environment with a preconfigured PHP app, such as an open-source forum software).
6) Barrier to entry in the modern computing world. You can't just launch a forum provider in 2022, you need to have both an iOS and an Android app, and they need to be as good as Discord. Your forum also needs to load on desktops with varying screen resolutions, from iPads which are essentially retro 800x600 displays, to 4k monitors on laptops and desktops.
You can see how these things all feed into one another. Forum hosting providers were eaten up by the likes of Tapatalk because the margins got so low, only a big fish could capture enough revenue to survive. Open-source projects fell apart because the VPS providers couldn't afford to contribute code to them anymore. People left for apps and social media because forums started to get worse. Etc.