Something like this should be default in MacOS. I use blackhole daily in my audio production and sound design practices. If you use a modern audio interface you might have a loopback available there.
macOS 14.2 implemented something like this in Core Audio, but it is not user facing (and also documented extremely poorly). You can create a "Tap" that can capture audio from a particular application, or subset of applications, or an output device. This can then be added to a private or public Aggregate Device (depending on the Tap being private or public).