In that case it's an issue with Youtube in your area, or something specific about the version of MacOS or Safari combined with Youtube.
Check if you can play a commercial HDR video. On Youtube query on "HDR Channel" plus "Dolby Vision", and play some of those. If Safari doesn't work, try Firefox. If it works, the Stats for Nerds output will show PQ or HLG, plus it should be visibly similar to local Quicktime playback.
Today I tried several commercial Youtube HDR HLG Dolby Vision videos on Safari 18.0, Sequoia 15.0 on an M1 Ultra Mac Studio and with gigabit fiber. It just didn't work. There is something wrong with Safari 18.0 and Youtube. Firefox (desktop version) worked.
All those combinations worked on Vimeo. This illustrates that HDR distribution on Youtube is just not mature and reliable on all platforms. There is nothing you can do about this, except switch to Vimeo.
A few years ago Youtube would not play at 4k in Safari, but would play in Firefox or Chrome. I think Youtube required the VP9 codec for the higher res material and Safari at that time did not support VP9.
It's conceivable that Youtube might be moving some of the HDR content to require the AV1 codec. I'm not sure Safari supports that but Firefox does. In some cases you can request AV1 by going to this page (in Firefox) and selecting "Always prefer AV1." The options appear in MacOS Firefox but not Safari. For other platforms and browsers, you'll have to test that. https://www.youtube.com/account_playback