There is no built-in way to do that.
You will need to create a new shared mailbox manually or with a script, and then mail disable the public folders and move their respective SMTP addresses to the new shared mailbox.
or 3rd party sotware:
https://www.codetwo.com/admins-blog/migrate-public-folders-to-shared-mailbox/