Some jobs (like software engineering) can be slightly more flexible. You'll probably need to work at a desk behind a computer screen all day, but where that desk is located, might not be so important depending on the exact nature of your work. If you don't like working at a desk behind a computer screen all day and believe this is bad for your mental health, then you may be in the wrong line of work.
We should remember that regardless of whether we're working remotely there's a lot about the nature of our work that is simply determined by the specifics of our jobs. I must work 5 days a week on a desk behind a screen if I want to be software engineer (like it or not). I'd argue this in my case this far worse for my health than whether that screen is in an office with colleagues or in my house with my family.
If people feel that remote work isn't for them then I think that's fine, but I also think they should just look for companies that are happy for them to work in-office or work hybrid. One of the nice things about remote work is that generally there are other companies out there (if not your own company) that will allow you to work from the office if you choose. When you compare this to people who are forced to work on roofs in the rain, or forced to work under cars in a car garage, or forced to sit behind a stirring wheel for hours in trucks, I think this hysteria about remote work being so "bad" speaks more to the privilege that middle-class white collar workers have. Although I don't want to dismiss anyone's individual struggles.
Again, I've worked mostly remote for decade and in my case it's been lovely. I get to spend loads of time with my partner and we've been able to take 1-2 month trips abroad a few times because I can work while we're away.
Even if you don't like or agree with remote work for yourself what we should all be in favour of is more choice in the labour market, and remote work for this reason should be celebrated instead of repeatedly bashed in the media for not always maximising worker productivity, and occasionally making people feel lonely.
Remote work is a good thing. Not because it's good for everyone, but because it's good for some people. If you struggle to mentally cope with working from your home, you may find most other places of work to be quite rough on your mental health too. I suspect in many cases this may speak more to things going on in your personal life than an issue with your workplace. Maybe the real issue here is that it's not healthy for us to live alone and in recent decades with we've replaced family life with work and with neither some people feel lost.