IMO master key policies are often very lax, usually because it's considered inconvenient to control the key. The more senior employees feel they are too busy to be bothered with controlling access to the master key ie signing it out to someone.
IMO the only way this could have been prevented is if he had not had access to the master key: Miya didn't encourage him, or go anywhere with him , or do anything to compromise her safety, but because he had the master key, she was helpless to prevent this.
It's very difficult for young women to complain about men who have an unwanted crush on them. It's usually considered a compliment. I remember when I was young, there was some very creepy behaviour that I didn't feel I could bring to anyone's attention, I just tried to freeze the person out, not make eye contact, etc. It's something that goes on under the surface in millions of young women's lives, all the time. She may have felt creeped out by him, but his employer wouldn't be able to fire him for that reason.
I do think that organizations have to realize how risky it is to give employees unrestricted access to other people's homes.