Import all media referenced in posts

  1. Can I use get_attached_media() to get the images referenced on a page, even if they’re not formally attached?

No, if they’re not attached they won’t be attached. I assume you’re talking about images in your posts that are offsite?

If so, you need to download them, create an attachment post, attach it to the post, then replace the URL in the conten

  1. Should I use media_handle_sideload() to insert the media into the library?

Yes, the sideloading functions will even create the attachment post and attach it to a given parent ID, although finding the images to sideload, and replacing the URLs is another matter.