To play YouTube videos in the background while doing other things on your iPhone, you can use YouTube premium or Safari's desktop view mode.
If you're annoyed by Facebook autoplaying videos, here's how to stop those videos from playing automatically on desktop or your phone.