All the details are available in this job
https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/clean_up_uploads.rb
TL;DR: an image is orphaned if and only if it’s not referenced
- in the latest version of a post
- in a draft
- in a queued post
- in a logo site setting
- in a custom emoji
- in a theme
- in a user avatar/background/card image
- in a category logo/background image