It renders a high-resolution image to a buffer, and then scales that when rendering to the actual screen buffer. The buffer image is at least as large as the actual screen buffer.
You can see for yourself that it isn't changing the hardware resolution of external monitors when scaling by taking a look at the actual resolution on your monitors OSD if it has done. It'll always be the native resolution.
If I tried all the possible scalings for my external monitor, the grey line around each window, to give a specific example of, is always a crisp physical one-pixel wide.
macOS creates a buffer to render to that is the same size as the physical output you're choosing to use, and is able to render with pixel precision in that buffer.
However, it is unclear to me what are the scaling ratios relative to the native resolution in your examples. In this article for Sierra you seem to be only able to pick integer factors: https://www.eizoglobal.com/support/compatibility/dpi_scaling...
Maybe? But that's ancient history.
I don't know what the ratios are - the UI doesn't expose them.
But this is all a bit arbitrary - I think the macOS API deals with an abstract 'points' unit.
Non-integer scaling (of a pixel source, vectors are different but not relevant here) either requires blending or crisp unequal-sizing artifacts.
First of all, DPI is not the metric we're interested in. That is a unit for print quality, and it has no relevance for an OS, for Photoshop, or anything we do on a screen. The operating system does not know how big your screen is. Inches nor dots are relevant; only pixels are. It would be more accurate to talk about the ratio of monitor pixels to apparent pixels. I guess Microsoft finally got the memo in Windows 11 (or was it 10?) and changed to percentages.
In MacOS, a 4K monitor set to 1920x1080 will still be 3840x2160, but it displays 4 pixels for every 1 apparent pixel. Everything scales correctly, except for legacy applications. The UI elements, text, etc. appear to be a sharper version of 1080p. In Windows land, this is the same thing as "200%." As far as I can tell, Windows does the same thing but uses scaling percentages instead of apparent resolution.
To go deeper into nitpicking, DPI is not even that misleading, if you take "inch" in DPI to be equal to 72 points as used in font sizes. Then a 72pt font on the screen with DPI X will be rendered with height of X pixels.
And yes, the OS does in fact know how big your screen is: https://en.wikipedia.org/wiki/Extended_Display_Identificatio...
https://apple.stackexchange.com/questions/193723/scaling-all...
If somebody understands the situation better on MacOS I'd be interested, but based on my experience, Windows is the only OS that gets this as close as possible to right. It's a single setting that affects all applications and I can set monitors independently and it will scale on the fly (even if it does look a little weird as you drag an app across and it dynamically shifts)
Every now and then I'll come across a app that doesn't quite deal with high DPI scaling correctly, but it is the exception to the rule.
Linux also works pretty well, but as with everything Linux, it's almost always "it depends and well, not quite" (not usually multi-monitor aware, lots of per app settings)