The point here is the order of expansion of macros.
In the first case, the macro expansion works as expected, X and Y are replaced with hello world, the preprocessor expands all three macros(CONCAT, X and Y), in the expression CONCAT(X,Y), to
_CONCAT(Hello, world) -> #Hello #world
and finally to
In the second case, the expansion of _CONCAT(X,Y), expands to #X #Y, hence the result.