While I agree with the comment saying the only thing you can do with a two year old is prevent them from accessing it, your 2 year olds reasoning also demonstrates why spanking them does not work reliably in that kind of instance either.
Kids that age are in some respect smarter than we often think, but in other respects they're totally helpless.
So he's understood that the oven is hot, but not that it being hot means he will hurt himself if touching it and that as a consequence he shouldn't. That's reasonable for him. He needs to make several other connections to determine it's bad: Many other things are hot, but not hot enough to be dangerous. He needs to also realise that too hot equals pain, and this means realising that touching the plate equals pain, not just hot. That's a step or two two long from starting premise to consequence for a 2 year old.
You'll see the same with kids that refuse to dress up when going out when it is cold out. It's hot inside. They've been told it's cold outside. But they also need to realise that this means they will be cold if they go out without dressing up even if it's hot inside.
Sometimes what works with very young children is to help them connect those dots. With my son I'd open the door, step out, so he can feel he's cold, and then tell him we needed to put warm clothes on to stay warm. Or you can be explicit in explanation: "we need to put clothes on so we stay warm when we go out" instead of "we need to put clothes on because it's cold outside".
For things that can be painful, try expressing that: that the oven will hurt. That it is hot, that's a separate thing (for now).
With a two year old you're not getting away from trying to prevent access, but my son certainly responded to just having the causal chains from "do things adults consider dangerous" to "will hurt" shorter.
Another strategy that keeps giving even now that he's 9, is to give constrained choices, and make him decide or decide what he thinks the right answer is: "Do you think the hot oven will hurt a lot or lots and lots?" (or when facing a 9yo that wants to decide everything: "do you want healthy dinner A or [marginally more popular] healthy dinner B?" as opposed to "what do you want for dinner?"). Choosing a specific framing is a scarily effective way of guiding them to where you want them to be (and it works scarily well on adults too; we're not nearly as much smarter than a toddler as we'd like to think).
I certainly can't say if the above works for you, but it's worth a try.