In a good charger they would (should) be. In many $1 chargers they won't be, but at least the charger will stick out of the wall where it constitutes less of a fire hazard even if it somehow fails catastrophically.
That's not the point. You could have Santa Claus or the good Lord Jesus have it installed. It'll still be a DIY contraption that you don't know how and when it'll fail, and if it will, the consequences are simply not acceptable in the light of what you're trying to achieve. Some things are just plain dumb and should not be done. Sorry for being rather direct about it, but it's just the truth! You're embedding a piece of live-AC powered equipment inside a confined space in the likely proximity of flammable materials like wood, insulation etc. That's just not a good idea.
So buy any of the properly engineered and certified smart switches out there on the market and interface them with your project. If you analyze these, you'll notice that these are designed in a fundamentally different way from your project, usually involving a non-insulated power supply that's much more simple, but in which component choice is more critical (esp. the capacitor whose reactance serves to drop AC voltage to the desired level). The inherent drawback of this is that the circuit is at live AC potential all the time, which means it's tricky/dangerous to work on it and to interface with for debugging etc. All reasons why you shouldn't be DIY-ing this.
What you're doing is NOT sensible and there's no way I'm going to encourage it by offering implementation suggestions. I'll leave this to others if they feel this is a responsible project, or they simply don't care what you do and believe it's your problem (which it is, but I think it's at least appropriate to point out that it's really not a good idea).
Definitely not suggesting that!!!!! Any competent electrician will outright refuse this btw. They should also outright refuse to install your DIY circuit inside a closed off wall.
You're suggesting cramming a device that dissipates 2.5-5W even in normal operation inside a wall outlet, that may furthermore see high-powered devices like vacuum cleaners etc. be plugged in. Mere contact resistance would further heat up things.
Just don't do this man, it's not worth it.
If you insist building your own switchable IoT outlet, then just put it in a casing with proper electrical insulation and ventilation, outside a wall with ample space around it. And please educate yourself on good practices in working with live AC.