How to prevent Chrome tabs or any kind of app from sleeping when in background?
No, it's designed like that by the app's developers, so you can't.

Though for YouTube, if you're rooted, there is a Xposed Module called Green YouTube that have an option to play music from YouTube in background (but it doesn't work on my phone).