IMO, it's a combination of intake, a fairly competitive peer group that creates these results.
A bright child would probably do well anywhere, but the environment does make a difference.
A friend's son in a local comprehensive does not want to stretch himself more because he is already at the top of his class and is not interested to put in more effort. However, in a set of bright students, it would be probably a competition all the time so that the child may like to put in more effort. No guarantee that constant competition would not have a negative impact.
Some non grammar schools have been able to achieve great results. I think teachers in all schools have an interest in their pupils to get good result. There are some great and some not so great teachers in all schools.
BTW, well to do family does not necessarily mean that they are more associated with the child's education
