I have installed Java runtime (17.0.8), set up the LanguageTool credentials in Tools → Options → Language Settings → LanguageTool Server, and made sure that LanguageTool is enabled for English in my settings, but the underlines under grammar errors aren’t shown.
What I had missed from that article is that I should’ve set a different API URL. I changed it to https://api.languagetoolplus.com/v2 in LibreOffice settings and it now works. I had to also disable the built-in offline Hunspell spellchecker.