I'm no legal expert. Are you? Common sense dictates that it isn't illegal. Publicly funded corporations and organisations have long-standing impartiality clauses. I'd be very surprised if these were discovered to be illegal after all these decades of their usage. The civil service serves the Government and the population. The civil servants support whatever political party is in Government in an impartial way. They're not allowed to get political. The BBC is a publicly funded broadcaster. The funding comes from license payers of all political backgrounds. So the BBC stays impartial. It's not a difficult concept.
There's no such thing as free speech unless you're speaking to yourself in a darkened room. Apart from that there's always the audience and the context to consider. We all tailor our speech depending on who is present, unless we have a serious personality disorder. All we say has to be within the law - the actual law I mean; not laws you've invented to retrospectively forbid impartiality clauses for the convenience of this debate. If you are working for the MOD or the Armed Forces or the civil service you will be bound by the Official Secrets Act. This Act impinges on your free speech.
In the hierarchy of free-speech constraints, one down from the law is rules. Someone working for a company developing a product can't go about blabbing about the product when it's in development and when its commercially sensitive. They will have agreed to a confidentiality clause. But that would limit the free speech of an employee surely? Well - yes, but there's no such thing a pure free speech. When you take money off an employer there's rules. When you contract with an organisation and take their money, there's rules and obligations on both sides.
Lineker is the face of BBC Sport. He has a responsibility to the BBC to remain impartial and not bring the corporation into disrepute. He hasn't stayed impartial, and arguably he's brought the BBC into disrepute by using inflammatory comments referencing the Nazis. He's a grade A bell-end in my opinion, but my opinion matters not a jot. What's pertinent is whether the BBC will turn a blind eye, or enforce their impartiality rule. We will see.