I have a load that is mostly played in Myshuno with 19 households. I've encountered about every kind of neighbor and random interaction at this point
Which apartment was it?
If you didn't give him a key to the apartment and it only happens once in a while then it's a myshuno fluke. Myshuno has a fair amount because in a way it's "open world" by district.
For example the spice district; if you invite your friends who also live in the spice district to hang out it often time considers them to be there already. Sometimes they'll come over and sometimes they are playing basketball but that's still considered a part of your "apartment."
However if you invite sim friends from the arts district to the spice district they all show up (so long as they aren't at work).
Occasionally this trips up npcs and they come inside and aren't really aware that they aren't in the "district" but an apartment. Like the npc could think it's a part of the basketball court and the prompt doesn't show up to send home because technically that's a street as well. A quick fix is to travel to another district and back. That seems to always reset the apartment and kick the unwanted guest out.
That said, uninvited guests is somewhat a Myshuno thing where neighbors can walk in if you've talked to them just outside the apartment. Be it the hallway or, again, the street is considered the same, they can walk in but there is almost always a prompt to send home if you started a chat with them prior to them coming in
They come over often to hang out, because they're bored, to workout, they want to have an intellectual conversation, a shower or to eat. They also come very angry when music is too loud. But on these specific visits they can't just come in unless invited.
A quicker way to solve unwanted sims in the apartment is to simply lock the main door and allow access to just household members and then unlock to allow friends in if you want them hang out.
I don't lock my doors, it's a part of the city life I've come to enjoy as the "extended" family. Plus they're all my sims at this point as I only left two original families in Myshuno, Diego Lobo and the Fengs. Everyone else was evicted.
If they get stuck without send home I simply travel quickly or travel with them and leave them at the place while sending my Sim home. Truly this problem is rare though, at least for me and I play Myshuno more than any world.
Baako Jang was the only sim who would barge in without having a chat outside first and he only did that in his complex. If it wasn't him, it was a district fluke/ mistake.