We are not really talking about the GM controlling the character's feelings, thought's and action in general. But ultimately I see no reason to differentiate how mental and physical tasks are handled. Mental restrictions (your character simply doesn't know how to do that) are just as real than physical restrictions and it is perfectly fine to enforce them in the rare situation it is needed.
But why is the GM the better source for what a character thinks than the player? You assume here that the GM has the superior position, but I don't see why that should or must be so. If the answer is to ensure proper playing, that's either something the player is on-board with and so doesn't need your help, or it's a problem because not everyone agrees as to what's proper playing. The GM isn't in charge of this -- it's a table issue, not a game one. If, as I see more often, the issue is to protect the GM's plot, well, the answer to this is evident -- don't GM that way and it won't be a problem. Regardless, it's not apparent that it's the GM's responsibility in game to enforce how the GM thinks the PCs should act.
One thing I was thinking earlier is that a player describing the action in detail or in parts can kinda break the action declaration logic. Like if the player just said: "my character tries to make gunpowder" you would probably call for some sort of skill roll if you assumed that this was something that was at all possible (let's assume that in this instance it is possible by the physics of the setting) or just say they fail because no one in the setting knows how to do that. If the player instead starts to list the ingredients and tells how their character combines them, then they just succeed? I don't think so. I think that in the latter case the player is actually trying to declare the same action, just in more complicated way i.e. the character is trying to make gunpowder, and should be handled in the same way. This same issue applies to any task which is physically easy to do and the real difficulty is knowing what to do.
Well, firstly, the latter example is a list of action declarations that the GM should adjudicate, so the difference between the two isn't one of kind, but one of
degree.
Secondly, the list of assumptions necessary for your chain of events to occur is pretty weird. You first have the GM establish that gunpowder as it exists in the real world also is possible, in exactly the same formula, in the game world. Secondly, this formula must be known to the GM, else how can they adjudicate it as exactly the same as the real world. Thirdly, the GM must be adverse to the PCs developing the gunpowder -- that the GM has allowed for in the world. Fourth, in your second example, the GM must both know the formula for gunpowder (according to the second assumption) but also not recognize that the player is instantiating it through these action declarations until the final result occurs. Finally, the GM here is assumed to have the ability to say no so long as the precise formula isn't presented, but be utterly powerless if the player says the magic words of the formula.
This is a weird set of assumptions that ends up still failing to make the point that the GM needs the ability to control PC thoughts to prevent catastrophe -- it's perfectly preventable even with most of these weird assumptions in place, it's only the last one, where you beg the question, that weirdness occurs. By this I mean that you include in your assumptions that not preventing "metagaming" causes problems only to discover in your conclusion that not preventing "metagaming" causes problems. Well, no wonder, you've assumed your conclusion in the premise.
I fully agree that the players being good sports is ultimately the key. If the GM actually has to often step in and say 'no, you can't do that' then there probably is some fundamental miscommunication about the premises of the game or the setting. That being said, sometimes wrong assumptions or miscommunication about the details of the situation or the setting happen and in such a situation it is perfectly fine for the GM to clarify things.
Clarifying things doesn't involve telling players what their PCs think, it involves getting on the same page as to the fictional positioning. Either side can bend -- this isn't a GM to player thing only. I've, quite often, realized I've failed at establishing a shared understanding and chosen to go with what the players understand rather than what I initially intended because it's easier to correct one person than a whole table of players.
This is a good point. A lot of people like to play D&D in rather gamist manner, as a game of 'solving' dungeons. In such an approach fussing about whether the character actually knows the monsters vulnerability might feel like an unnecessary burden. That being said, this goes back to what I have said may times: it is not good idea to make plot critical mysteries that hinge on things that the players actually know but their characters don't. Thus when setting up a mystery, whether it was what weapon can harm the monster or who the murderer is, the GM should endeavour to build it in a manner that such an discrepancy doesn't exist. I still feel that this is not the same than the players adhering to more tangential limitations of their characters' knowledge i.e. 'no one in this setting knows how to make gunpowder,' 'my character is uneducated idiot from backwoods of nowhere and thus cannot describe the exact details of the political system of Thay'
My 5e games aren't gamist at all. If I was playing Moldvoy Basic, then they'd be very gamist. The rulesets, despite both being D&D, are very different. Still, my players knowing about trolls means that forcing them to pretend they don't with some new characters is pretty boring and frustrating, so we skip that. We skip worrying about anything but portraying the character how the player wishes to portray the character. I don't police this. And, lo and behold, I get players that have deep and rich characters, and put their character's desires to the forefront. I get this because I engage those characters, make their wants and goals matter so there's reward for playing to those, and don't worry if I don't understand why a player might chose a certain actions. I might ask, out of curiosity, but not to correct or change. I don't need to understand why, I just need to be able to adjudicate the action. If I present challenging scenes and don't predicate those challenges on secret information the players already know, then I get great roleplay and engagement from my players -- all without ever once worrying about "metagaming." If my players guess, or know, something already, that's no sweat off my brow -- I've got infinite dragons. I can let that one go and do better next time.
Honestly, I'd suggest getting out and playing in a game that isn't D&D. I'd recommend one of the PbtA games, or a FATE game, run by someone that really loves those games and has experience with them. Experience a game that's very different from D&D -- it'll make your D&D game better. Even if you chose to change nothing, you'll better know why you like the things you do.