i.e: The answer to "why" should never be "because I said so".
I get that many kids will just ask why infinitely, and lots of parents say that because they are fed up and know the child isn't taking on board the answer, but I'd recommend instead insisting on a specific question - when they ask "why", ask "what don't you understand?" or drill down. This has the advantage of potentially catching a real miscommunication where the child doesn't understand something but truly is trying to work it out, and tends to remove an easy annoyance of the "why" forever.
If the child isn't old enough to understand that cooker == hot and hot + hand == pain, clearly you have to stop them touching the cooker, but that's not mutually exclusive with helping them understand why, if possible.
I remember my parents teaching me not to put my fingers in the door frame when it was open by putting a carrot through and letting me close the door, slicing the carrot in half. I wasn't afraid of punishment or following a rule - I understood why I shouldn't do it, so I didn't.