Both M's true identity and her identity as M are not top secret, but the connection between them is to be kept secret.
That's the point of their conversation, M stops Bond exactly where he would make the link (in case anyone was listening in on their conversation).
Think of it this way: both Batman and Bruce Wayne are publically known people The only secret that is kept is the connection, that Bruce Wayne is Batman, i.e. the link between the two otherwise publically known people.
And yet in "Skyfall" we see her appearing in an inquiry where her name - even if not uttered on screen even once - must be well known to everyone present, and there are various ministers (including Gareth Mallory, played by Ralph Fiennes), and even some members of the press with cameras and IDs, which contradicts the secrecy of M's identity.
There is actually a very recent real life example here.
During Michael Cohen's trial, Donald Trump was referred to as "Individual 1" to prevent leaking his identity.
They did this even though it didn't actually keep Trump unidentifiable. The trial ended up exploring the fact that "Individual 1 won the 2016 presidential elections", and the winner of those elections is obviously Donald Trump. However, if the presidential elections had not been the subject of the trial, then this would never have been established, and Trump's identity would have been (reasonably) concealed from the trial itself.
The same applies to M here. Obviously, some people know M's identity. If no one knows something (even if it's top secret), then the knowledge (and the secret) doesn't exist.
an inquiry where her name - even if not uttered on screen even once - must be well known to everyone present
While there may be some who know M's name, that doesn't mean that M's name was made public during the trial. Maybe she was simply addressed as "individual 1" during the trial, but the script simply glossed over that.
You also need to consider why the secrecy is used to begin with. It's intended for operational security.
Let's say it's publically announced who is Head of the Secret Service:
mzywiol is the new head of the Secret Service
In the meanwhile, an enemy spy gets their hands on some of the secret service's documents:
008 was injured during operation StackExchange. They are recovering from their wounds in site zulu. M will debrief them.
There is nothing that establishes the public person (mzywiol) as a particular person in the leaked document. Maybe you're 008. Maybe you're M. Who knows?
Even if you know every person who works for the secret service, but not their codename, then that document doesn't tell you anything. Who is injured? Who is meeting them? Where are they meeting them? ALl important information is obscured behind codenames.
As there are more than 26 people in service of the Secret Service, you can't just assume that everyone gets their initial as their codename.