It is listed as an extended procedure but I found the following which clears things up. However, it does work from within a function when the function is executed with EXEC but...
Since sp_executesql is an extended stored procedure, I can run it from within a function and I am able to using the following which returns the expected result: