You could just lock it, but then he's probably just going to ask you "Why'd you lock the door??" In which case, simply say "Because you kept walking in without knocking, which was rude."
Or you could stop him immediately the next time he does that, and say "I would appreciate it if you'd knock and wait for me to say 'come in' the next time. Thank you." -- a STATEMENT, not a question.
If he says "But I ALWAYS do that," then say "Yeah, you 'always' lived here, and 'always' were faithful, too, but let's not go there and ruin a perfectly good day, shall we??"