If the function returns an nvarchar(max) which contains 'col1, col2, col3', then pass it to stored procedure as a parameter called "@columns", where you can build and execute a dynamic query like this:
declare @q as nvarchar(max) = concat('select distinct ', @columns, ' from MyTable')
exec (@q)