YouTube still charges users to play videos in background on mobile devices. However, we can use add-ons to manipulate the APIs that YouTube uses to determine whether it’s in background.
Just download Firefox from your favourite app store, if you haven’t already, and visit this page to install the add-on.
Open YouTube and start a video. You should now be able to lock your phone or exit Firefox without the video stopping.
If you also want to remove ads, install uBlock Origin.
This way you don’t need to access YouTube in desktop mode, change your user-agent or do anything else.
The code is available on GitHub.