I occasionally do this from Carbon Copy Cloner backups or by archiving ~/Library/Mail folder. ~/Library folder is hidden by default. When booted to that macOS it can be revealed by holding down Option-key when selecting Finder > Go > Library. Or, when booted to another macOS volume by revealing hidden items via Shift-Command-. (that's a period at the end).
So with Time Machine restore that ~/Library/Mail folder (I don't use TM so I don't know the details for that).
Then import that Mail folder to another Mac or to a new macOS install:
Mail.app > File > Import Mailboxes... > Apple Mail > choose that copied Mail folder > choose all Items.
On the left-hand-side under "On My Mac" > Import, ..., look for and move "Local" and all mailboxes inside it up under "On My Mac". In my setup I right-click and delete "Import" Mailbox (it has gmail mailboxes that are online). YMMV.