Translation:The boy is not going into the room, but into the dining room.
It's a matter of determining what needs to be closest to the verb stem.
In this sentence the important thing you're trying to tell the listener is, "NOT the room, but the dining room" (never mind for the moment that this pair of words doesn't make a very good contrast with each other).
For that reason, nem a szobába needs to be immediately before the verb stem, and the be- prefix must be moved out of the way for it.
A sentence that's just about the action of going into the dining room could keep the prefix in place:
Bemegy a fiú az ebédlőbe.