Sonarr v3/v4 lets you set with “must contain” or “prefer” keywords. Adding x265 or hevc to the “prefer” list tells Sonarr to give higher scores to x265 releases, but still download x264 if no x265 exists.
Wait—what about AV1? It's newer but less compatible. To ensure x265 wins over x264 but loses to a better codec, set these scores: sonarr prefer x265