Wrong result returns when Subquery is unnested

A couple of days ago I got a request to take a look at one SQL query, which obviously returns the wrong result. The database version is 12.2 running on Windows on Azure Cloud. Simplified for the demo purpose it looks like this – the query returns 1 and 2, but it should return 1, ...