Synopsys Synthesis with underlying modules as gate libraries
The problem has been fixed by the compile_ultra command as mentioned in the comments. Here is some explanation.

If the compile command is used, ungrouping is disabled by default. So it should be enabled explicitly.

compile -ungroup_all


On the contrary, auto ungrouping is enabled by default if the compile_ultra command is used. No additional option is required in this case.

compile_ultra