Simple answer
When in a group of like minded individuals, you tend to push yourself harder, so you are not looked upon as the odd one out. Physiological im afraid.
And if you train at home alone, well its easy to put things off until later, or next day, or next week. Until, because of a lack of results and eventually boredom, you quite simply start to lose interest.
I will join a Gym ,you tell yourself. When I get the time , but not just yet. Next week , or perhaps next month, and on it goes
Put simply .. The Gym is great. So is working out at home, if you are serious enough
I personally use both. But, if you have little or no experience, then a good not so crowded Gym with at least one good instructor to build your programmes and diet is best