Following a successful assassination, the assailant must immediately secure a safe getaway. A calculated escape plan is put into motion, relying on precise physical actions to buy precious time and deceive the royal guards.
Leaving the cool upper chamber where the king resided [מצודת דוד], Ehud steps out into an antechamber. The primary approach among commentators is that this space is a corridor or portico situated just outside the inner room, typically arranged with chairs for people waiting to see the king [מצודת ציון, מלבי״ם, ביאור שטיינזלץ, אברבנאל]. As he exits, he pulls the doors shut behind him, sealing the slain king inside. This specific act of closing the doors behind oneself is compared to the way God closed the doors of the ark behind Noah [מצודת ציון, רד״ק].
Merely shutting the doors, however, is not enough; he takes the extra step of locking them with a key [רש״י, מצודת ציון, רד״ק, מלבי״ם]. To execute this deception flawlessly without raising suspicion, the locking mechanism itself plays a crucial role. One approach suggests the lock was designed to be operated with a key from either the inside or the outside [רלב״ג]. Another perspective explains that the doors featured a self-locking mechanism; simply pushing them shut locked them automatically from the inside, meaning a key was only required to open them from the outside [אברבנאל].
The ultimate goal of locking the doors is to create a perfect illusion. Because the outer waiting room happens to be entirely empty of people at that exact moment [מלבי״ם], the sight of the locked doors leads the king's servants to a natural conclusion. They assume the king has locked himself inside for privacy while relieving himself [רלב״ג]. This carefully constructed ruse prevents the household staff from walking in unexpectedly and discovering the scene. By forcing the guards to hesitate and wait outside the doors for a prolonged period, the assassin gains the crucial delay needed to escape safely [רד״ק, ביאור שטיינזלץ, אברבנאל].