Mac OS doesn't automatically switch the sample rate according to the source. It is always fixed to what is set my the audio midi app. Finally there is an application that runs in the background and changes the sample rate automatically based on the source sample rate
darko.audio
You can download the app from here
github.com

LosslessSwitcher adds bit-perfect Apple Music playback to MacOS | Darko.Audio
A neat little app from an independent software developer.

You can download the app from here
GitHub - vincentneo/LosslessSwitcher: Automated Apple Music Lossless Sample Rate Switching for Audio Devices on Macs.
Automated Apple Music Lossless Sample Rate Switching for Audio Devices on Macs. - vincentneo/LosslessSwitcher