To put it simply, no one is allowed in or out because "The 'RED DEATH' had long devastated the country", & Prince Prospero's sole reason for bringing "a thousand hale and light-hearted friends" into his castle is to remain immune from the disease. The measures to which the prince goes to keep the illness at bay are remarkable:
A strong and lofty wall girdled it in. This wall had gates of iron. The courtiers, having entered, brought furnaces and massy hammers and welded the bolts. They resolved to leave means neither of ingress or egress to the sudden impulses of despair or of frenzy from within.
So, the wall and the welded doors assured (or so the prince thought) that no one could enter or exit the abbey. Thus, all those inside "might bid defiance to contagion." They wouldn't worry about those folk dying a horrible, bloody death outside; instead they would party. After all, they had all the entertainment they could want:
There were buffoons, there were improvisatori, there were ballet-dancers, there were musicians, there was Beauty, there was wine. All these and security were within. Without was the “Red Death."
So, the wealthy are safe and secure...or are they?
In "The Masque of the Red Death," Prince Prospero does not allow anybody in or out of the abbey in case they contract the Red Death and pass it on to others. Remember that the Red Death is a form of plague which is incredibly destructive: it has wiped out much of the country's population, causing pain and suffering wherever it goes. Moreover, when a person catches the Red Death, the chance of recovering is so slim that it is almost impossible:
No pestilence had ever been so fatal, or hideous.
For Prince Prospero, the only way to prevent its spread and to protect those he loves is to keep them as far away from the Red Death as possible. This accounts for his decision to keep people inside his abbey and to prevent them moving in and out freely.
He keeps his guests amused by throwing a masquerade but the Red Death is never far away: in fact, it appears as a guest to the party.