SQL Server: Recursive dynamic SQL puzzle
I am curious to know how the column names getting concatenated.


Can't really answer that. Some internal workings of SQL Server creates a result like that, sometimes.

The technique has been around for a considerable amount of time. Microsoft does not support the functionality and advises not to use it.

From SET @local_variable (Transact-SQL) 


  Do not use a variable in a SELECT statement to concatenate values
  (that is, to compute aggregate values). Unexpected query results may
  occur. This is because all expressions in the SELECT list (including
  assignments) are not guaranteed to be executed exactly once for each
  output row.


Instead you can use a cursor or the for xml trick to do the same.

declare @a as varchar(4000);
set @a = 'xxx ';

set @a = @a + (
              select quotename(COLUMN_NAME) as '*'
              from INFORMATION_SCHEMA.COLUMNS
              for xml path(''), type
              ).value('text()[1]', 'varchar(4000)');


Result: xxx [city][id][name]