Is there a way to electronically protect a device from bad chargers?
with simple electronics you can protect a device from fake, bad or even malicious chargers.

For sure that is possible. Up to a certain limit of course. The main properties of a charger are the voltage it supplies and how much current it can deliver while maintaining the voltage.

If the voltage is too low, then charging cannot and will not happen as the current will not flow through the charge controller (inside the phone) into the battery.

If the voltage is a bit too high it is not a major problem, usually the normal circuits can take care of that already.

For voltages above what the normal circuitry can take care of you do need extra protection measures. There are several solutions for this including (non)recoverable fuses. It all depends on how far you want to go, how much money you're willing to spend on this protection.

And regarding the current from the charger, the only issue is when it cannot deliver enough current but then charging will simply take longer or stop altogether.

As Passerby mentioned, the Note 7 debacle had nothing to do with the charger or using "3rd party" chargers. It was Samsung's marketing/management department(s) wanting to squeeze in a large battery in a space that is too small for that battery so that the battery did not have any "breathing space". The engineers must have known that these batteries need that "breathing space", as that is common knowledge. Source for this: Wikipedia