I had a strange scenario today and I can't reproduce it.
I changed current database to adventureworks and ran following code
DECLARE @SQL NVARCHAR(200)
SET @SQL = 'SELECT DB_NAME()'
EXEC sp_executesql @SQL
The sp_executesql statement returned "master" and exec statement returned "adventureworks".
Anyone knows why?