how does your character know that he'll need to provide his own magic weapon? And going back a step, how does he know that he will even require one?
The character may not, but the player in D&D has generally expected to pay attention to the fact that s/he playing a game.
And magic items are part of that game. From Gygax's PHB, pp 22 and 32:
Fighters can empy many magical items . . .
The following strictures appy to paladins . . . They may neer retain more than ten magic items . . .
Monks, much like paladins (qv), may not retain more than a small fraction of whatever treasure they gain. A monk may posess no more than two magic weapons and three other magic items. . . . Magic items usable by monks include [a rather limited selection]. No other magic items of any sort may be employed by monks.
I think it's pretty clear that Gygax expected players to think about access to magic items as part of buiding their PCs!
Why does your character know he is in a game, so he can make his life choices accordingly? Is it like the Matrix? Or trained in some Hunger Games style fashion? Or how do you explain it? What is the in-game explanation for your metagaming?
If it had an ingame explanation it woudn't be metagaming, would it! Which makes your question somewhat oxymoronic, I think.
"Optimization" is a pretty way of saying 'metagaming during character design'. Is it not?
PC building is, in general, a metagame process. Choosing to write "buttefly lover" on my PC sheet because I think it will be fun to play someone who loves butterflies is just as much metagaming as choosing to write "STR 18" on my PC sheet because I think it will be fun to add +4 to my attack and damage rolls.
There are PC generation systems which are mostly free of metagame - eg Classic Traveller - but D&D doesn't have them. For instance, you get to choose your race, which has mechanically significant consequences. What decision by the character do you suppose that corresponds too? None that I can see.
My Pathfinder character did not choose to be a kitsune or to be fey-blooded, or probably to some extent a sorcerer at all.
Right. Most PC building is not about playing a character. It's about deciding what character to play. This is generally connected to expectations of interest and enjoyment.
if the DM and the system wants me to be not mechanically optimized, it needs to reward me for that. Yay, you put points into Profession: Midwife! That might actually matter in the game! Not just make me feel like I choose poorly when bad things happen in the game because my character is not optimized enough and enemies get past him to the wizard or he can't deal enough damage to the BBEG.
I think this is the most important point for this thread.
If you want the players not to optimise, you have to create priorities for play other than mechanical success. For some player, immersion in the GM's narrative is a priority in itself, but it seems that your players want to play a more active role in the game. There are two main ways I know of (and probably ways that I don't know of) of helping active players prioritise things other than mechanical success. One is to fudge the dice to blunt the consequences of mechanical failure. However, this sort of fudging runs the risk of turning active players into passive ones.
Another approach is to change the way you narrate the consequences of mechanical failure. "Fail forward" can be a useful technique.
I don't mind optimization at the table and expect it, however it can suck what makes the games entertaining for me out of the game.
Usually it leads my players to want to speed through the levels because they want that next optimization point over just having fun playing the game - including failing and having things go sideways.
<snip>
I found it very unentertaining as a DM. <snippage> Find a good effective combo and repeat ad nauseum.
It sounds to me like you have three issues.
One is about the boring repetition of effective combos. I'd suggest trying to design situations that encourage your players to break out of those combos - eg in the context of combat, think about terrain and the mix of enemy forces; in the context of social conflict look for ways to engage the non-bard PC (eg a nemesis calls him/her out or starts taunting him/her). If in fact the maths is such that the players have no real prospect of success if they depart from the optimised combos, then you might need to revisit the maths of your encounters. (But 5e is meant to protect against this via bounded accuracy, I think.)
The second issue seems to be about player wilingness to have their PCs fail. Generally, D&D is unforgiving of failure because the default consequence for mechanical failure is PC death. You might want to look at techniques for ameliorating that, and also look at how you communicate to players that you have adopted such techniques.
The third issue seems to be that the players are more interested in the mechanical aspects of their PCs then in the ingame fiction that the game is meant to be focusing on. I guess one solution would be to make the mechanical aspects of their PCs more boring, but that might be a somewhat pyrrhic victory, especially if your players don't like the mechanical nerfing. (Unless you think that they are being distracted by the mechanics against their better judgement, and will thank you for taking away the distraction that is getting in the way of their enjoyment of the fiction.)
Another solution is to find out what would make the fiction more interesting for them and trying to introduce more of that into your game.