Jim Rohn said you are the average of the 5 people you are closest to.
James Clear said a well-designed system always wins.
If you want to get in shape and stay in shape, you have to have the systems to do so. I believe building that system around a community is the best way for long-term sustainability.
The community expects you to show up.
When people willingly join a community there's an understood and sometimes explicit commitment to showing up. When you have an expectation to show up tied to your goals - in this case, physical fitness, it increases the odds that you will get there. And getting there is more than half the battle. Odds are very high that if you walk in the door you are going to do the workout.
Peer pressure becomes a positive thing.
Once in the community and working toward a fitness goal together, peer pressure can become a positive thing. When you see your gym rival (typically a good friend you are on a similar level with), pushing their weight or reps a little bit, it will push you to join them. The caveat to this is always ego. Keep the ego in check, it's the thing that causes most injuries.
They celebrate your wins.
The true competition is always with yourself and congratulating someone else never takes away from your own wins.
The reality at this stage in life very few of us are winning competitions, and if they are, it's unlikely to be at a professional level tied to livelihood. To see your friend attain a personal record or place first on the leaderboard is worth celebrating.
And... it will push you harder next time!
Not only does having a community focused on fitness help you attain physical goals, but it also helps another very difficult thing in mid-life... finding new friends.