The fix I've found for this is to set a development team in my Xcode project, rather than leaving it as "none".
- In Xcode, select your Xcode project to see the project's property viewer.
- On the left bar, select your project's App target in the "Targets" section – mine's called "TreeView".
- Select the "Signing & Capabilities" tab at the top – it's the second one along.
- For "Team" select your personal team.
I found this solution from a link about macOS Sonoma sandbox security.
As the link states, it's not clear if there's some other settings to allow a project without a team (eg, distributed from a git repo, say) to be run without clicking this dialogue all the time. If you've got a more in depth answer than mine or can clarify extra details, I'll happily check yours instead of mine.