When I was coaching HS in Houston this was a pretty common occurrence and I've been on both sides of it a good number of times. It's honestly a really challenging thing to manage.
Personally, when we were the better team, I wanted to avoid embarrassing the other team, but I also didn't want to lose the utility of the moment for my own guys. So I'd empty the bench (even occasionally playing a man down), move kids to their less preferred positions (but not places where they would be a detriment to the team), and set realistic goals on specific things to focus on (playing the ball in from wide, playing out of the back, working at switching the point of attack multiple times). Now that the short-term goal is accomplished, focus on improving for the next game. And I'd sub guys off for being selfish *******s. Edit to add that we still tried to score. I don't believe in removing the ultimate goal of the game, but I would add in restrictions or sub-objectives to make it more meaningful for our development.
When we were the worse team, I would take off guys who were injury worries or who were getting frustrated. Lots of rotation to keep it fair. Give the team realistic goals to work towards (man-marking, correct body position, no fouling, stringing short passes together, etc.) and take the focus off the score. Stressing long-term over the short-term goals of winning. As a coach, it's easy to go into your shell when your team is getting waxed too, so coach your ass off so your players can see you care about them and not just the score. Encourage them through it, but also correct their mistakes to improve long-term.