Is it ok to lock a 5 year old out of a bedroom at night so you can sleep?

No. While your child is locked out of your room so that you may sleep. Someone could be taking your baby from his room. Why does your child feel a need to come to your room. It would be wise to maybe read him to sleep at night. Put him to bed at the same time read a story that is interesting to him. Do things in the waking hours that would tire him. After dinner allow play time then get the bubble bath ready with a few toys in the bath. Get one of his favorite books (by the way a trip to the Library is can be a fun outting. He'll meet other children his age and will be anxious for the next trip) and read him to sleep maybe having a stuff bear or something as a pal will be company in for him or her. Certainly never lock him out let him know every day how much you love him and that you are always there for him in the play ground or in the house. you are not only his provider you are his PROTECTOR.