The execution context is different. Within the REPL we are working line-by-line (Read, Eval, Print, Loop), which allows an opportunity for global execution scope to change in between each step. But the runtime executing a module is to load the modules code, and then exec it within a scope.
In CPython, the builtins namespace associated with the execution of a code block is found by looking up the name __builtins__ in the global namespace; this should be bound to a dictionary or a module (in the latter case the module's dictionary is used). When in the __main__ module, __builtins__ is the built-in module builtins, otherwise __builtins__ is bound to the dictionary of the builtins module itself. In both contexts of your question, we are in the __main__ module.
What's important is that CPython only looks up the builtins once, right before it begins executing your code. In the REPL, this happens every time a new statement is executed. But when executing a python script, the entire content of the script is one single unit. That is why deleting the builtins in the middle of the script has no effect.
To more closely replicate that context inside a REPL, you would not enter the code of the module line by line, but instead use a compound statement:
>>> if 1:
... del __builtins__
... print(123)
...
123
>>> print(123)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'print' is not defined
Naturally, you're probably now wondering how to remove builtins from within a script. The answer should be obvious: you can't do it by rebinding a name, but you can do it by mutation:
# foo2.py
__builtins__.__dict__.clear()
print(int) # <- NameError: name 'print' is not defined
As a final note, the fact that __builtins__ name is bound at all is implementation detail of CPython and that is explicitly documented:
Users should not touch __builtins__; it is strictly an implementation detail.
Don't rely on __builtins__ for anything serious, if you need access to that scope the correct way is to import builtins and go from there.