What happens if you requested website.com/subsubpage/? Expected result is the page in question is shown and the browser address field is rewritten to website.com/mainpage/subpage/subsubpage/
Your site’s permalink setting is just /%postname%/, right?
This 404 you get is the WordPress themed nothing found sort and not a generic, plain server 404 page, correct? If so, the related query for the page has somehow failed. Install and activate the Query Monitor plugin. After requesting the subsubpage, filter the queries in the monitor for caller get_page_by_path().
The query should find 3 rows. The data returned is used to determine the ID of subsubpage, which is used in the main query to get the page. If 3 rows were not found, there’s something off with the query made, like additional, unneeded conditions that cannot be met. Any such unneeded conditions could be a clue to the root cause. The query should be something like
SELECT ID, post_name, post_parent, post_type
FROM wp_posts
WHERE post_name IN ('mainpage','subpage','subsubpage')
AND post_type IN ('page','attachment')