Yeah, remote work seems to be a double-edged sword for productivity. As you say, the quality of life/work improvements are great, but the motivation and accountability and shared situation of a co-located team can provide the morale and accountability that push you to actually be productive.
I think remote work can theoretically be a lot more productive for solo-ish tasks like coding. On some days this is definitely the case for me, after I pull marathon coding sessions that likely couldn't have really happened so smoothly in an office setting. For some days or weeks where I'm consistently in the "zone", I really feel like I've gotten more done than I could've if I spent those days in an office.
But in practice, unless you have very high self-discipline, you're probably going to be battling motivation and boredom to some degree on a daily basis. You often might in an office, too, but it's not the same. In an office, you see everyone else working around you, probably talking about work, some of whom can see your screen (maybe not ever actually looking, but still in line of sight), and that's a potent cocktail for human psychology. At home, you're in or right near the same place you watch TV and movies and relax and sleep, alone or with your SO/family, and there's probably nothing really going on around you, so the environment is basically the same as your non-work environment. There's nothing around to light a fire under your ass.
I also prefer remote work, but I'm definitely trying to find ways to feel more motivated and symbiotic, and am interested in ways a manager or employer could help foster that for remote employees. I've been trying to work from coffee shops more, and that sometimes seems to help.