Why can this ENV not be found when it is defined in one layer using a Dockerfile?
The ENV keyword will be translated to export command (builin of the shell usually), if you remove the multi-line declaration you end up with this equivalent:

export A=123 B=$A


What happens here is that when the shell parse the line to give it to export input, A is not yet exported and available as an environment variable.

Step by step this will give:


You type export A=123 B=$A 
The shell parse the line and pass A=123 B= to export's stdin
export parse each argument in the form key=value and as such export A to be 123 and B to be empty


On the second form, A is available to the shell when the line is parsed, and as such the resulting export's stdin is B=123