I don't think it's right to say following the code of practice provides a defence to a conntravention of the Equality Act 2010.
The Equlity Act 2006, which is the statutory basis for the EHRC, says that a code of practice (written by the EHRC and approved by Parliament etc. etc.) shall be taken into account by a court or tribunal in any case in which it appears to the court or tribunal to be relevant - nothing stronger than that.
To my mind that means that could affect how a court or tribunal views damages and awards; it can't weigh on whether a contravention of the act was done or not.
One might also note that the CoP is carefully worded not to say you "must" or "must not". You will find a lot of "is likely to" and "is unlikely to", instead. It's important the the CoP doesn't appear to give the final word - that is reserved for the Act.
The 2010 version of the code tries to make this clear. I think the new one will do so too.