If you’re motivated at home you can run on street/walk/trails, you can do core body workouts, you can get some cheap equipment that will get you most of the benefits of a gym at much less cost. You can always find cheap used equipment for sale from people cleaning out their houses
Going to the gym gets you better equipment, more equipment, and helps establish a routine to keep you going when motivation isn’t enough.
If you get home equipment similar to what you’d use at a gym, the payback time is much longer, it may be difficult to move or store, and you can’t get rid of it when it’s time.
At home I have a good set of dumbbells, an Exercycle, and exercise mats I never use. However I’ve never really been able to establish a gym routine so that’s a waste of money. My brother has a good half ton of exercise equipment he’d give me free of charge but I have no way to transport it and it would cost too much.
I actually am considering getting more home exercise equipment. At least my teens would use it and maybe I would too. It’s expensive but it’s not continuous cost like a gym would be.