I agree locking the doors and threatening to lock the doors is not the way to go. It'd just make him panic - kind of naturally. He could see you saying you'll lock your doors as meaning that he couldn't get to you, no matter what, he'd be all alone in the scary, dark house and you couldn't hear him even if he really needed help.
Obviously, that's not the case, but from a five-year-old's perspective, that may be just what he hears, which could make his nighttime neediness worse, even if you don't lock the doors - if he feels the need to check to make sure.
I'd simply tell him, before bed, that we all try to stay in our beds to sleep at nighttime. Then, if he comes in, just quietly, without engaging with him, walk him back to bed, see he gets in, give him a reassuring pat, turn around and leave. Don't discuss things with him, don't reward the getting up with extra attention, hugs, stories, etc.
However, I wouldn't try to stop his coming in by threatening or telling him flat out to stop it or x, y, z. He's clearly doing it because he's waking up in the middle of the night and feeling anxious enough to need to seek you out, even though he knows it's making you angry. He's only five, he's having enough anxiety to get up and need to come find his parents to reassure him and comfort him.
I wouldn't give him extra attention, which may reinforce that this behaviour will be rewarded, but nor would I shun him. I think a pat on the head and a walk back to his room, pull up the covers and walk out is enough to convey 'it's fine, we're here, you're ok' without giving an incentive for doing it more than he needs to. At the moment, it appears he needs to. That's ok. He needed to disrupt your sleep when he was an infant. He'll probably disrupt your sleep coming in in high school, such is life.
