Everyone keeps saying that, but it's simply not true.
We have understood how this is not true for decades or even hundreds of years, and it's not even some impossible concept to grasp.
All that's required for a trait to persist, is for it to benefit the pool, not the individual.
The only way the seemingly obvious but incorrect idea you descibed applies is, a trait which is good for the group at the expense of the individual, if it's 100% effective like sterility unlike say alarm-calling which merely carries a risk for the individual, is that such a trait can never grow to where all members exhibit it.
But it can absolutely be strongly selected for maintaining whatever the optimal percentage is. IE, if it benefits the pool for 10% of members to be sterile, then the percentage of sterile members will not decrease through the mechanism you and so many imagine, but will stay at 10% for as long as the benefit exists.