I don't install many Safari extensions, but this is a good one.
Vinegar is a Safari extension that replaces the YouTube player with a minimal HTML video tag. It removes ads, prevents tracking, restores picture-in-picture, and keeps videos playing in the background.
It works across iOS, iPad OS, and Mac OS. Check it out here.