A family of Microsoft word processing software products for creating web, email, and print documents.
Dear Eero,
As the bookmark isn't supported in Word for the web, the error message may appear when you open the document A by inserting the bookmark link by the SharePoint Online file URL like https://contoso.sharepoint.com/sites/TestCommunication/Subsite2/Shared%20Documents/DocumentB.docx#bookmark1 in Word for the web or in the Word application.
As a workaround, I suggest you sync the both files with the OneDrive sync client first, define the bookmarks, open the both files from the local sync folder and define the bookmark links like C:\Users\username\contoso\Subsite2 - Documents\DocumentB.docx#bookmark1 by clicking on Links>Current Folder>Browse for Files>selecting the local sync folder>selecting the document B from the local sync folder>Bookmark>selecting the bookmarks>autosaving the files.
Then setting the files to be opened in the Word application by default in SharePoint Online and then you can click on the bookmark links in the document A to go to the desired places of the document B and any updates on the document B will be synced to SharePoint Online.
Thanks for your understanding and have a nice day!
Cliff