How do I include pre-installed images in a theme?

As per comments of @TomJNowell you can include images as files with your theme, but you shouldn’t automatically insert them as attachments in the database and neither should you generate pages on theme activation. The user might be just checking out your theme and end up with stuff in his database het doesn’t want.

What you could do is include an option with your theme, allowing the user to choose whether he wants images and pages preinstallend on his theme. There are three functions you will need for this:

  1. media_handle_sideload to transfer the image from your theme’s directory to the uploads directory and make entries in the database
  2. wp_insert_post to generate a page/post
  3. set_post_thumbnail to make sure the image you have handled under 1 is attached to the post you generated under 2. You will need some clever logic to keep track of ID’s in order to get to this step.

Depending on what your images are supposed to do, you may skip steps 1 and 3 and simply insert the images in the post content, loading them from the theme’s directory.