Terrible. I would consider filing a police report or at least touching base with them.
As a security guard, he might have had a way to get around the deadbolt on your side. If someone dies from natural causes, or is otherwise incapacitated, and the doors are bolted, obviously properties need a way to get in. Using a door wedge is the only protection.
Luckily, most crimes like this are burglaries not attempt to harm. That said, it's surprising and disturbing he stuck around until you woke up.