When initially figuring out what the “problem” actually is then it is better when people are together.
When the problem has been well defined, and people just need to run with the project: work from home is better.
If project needs pivoting or redefining, back to office is again better.
The further along a project is, the better work from home becomes. This is because all members of team have a solid foundation of why the project matters, so they can be free to work with less interactions.