Heming,
I have a script that does something similar, but rather than creating a feature class in the scratch.gdb, my script creates a new file geodatabase in the the scratch folder and uses feature class to feature class to populate features while applying a query. The geodatabase is then zipped so it can be downloaded by a user.
You could try creating a new file GDB in the scratch folder and populate the feature class using Feature Class to Feature Class in the new GDB rather than using the sratch.gdb.
Alternately, rather than populating with Feature Class to Feature Class. You could create a new empty feature class in the sratch.gdb using Create Feature Class, setting your input or feature set as the template feature class (so the schemas match) . You could then use the Append to add the feature set (or a feature layer to which you apply your query) to the newly created feature class.
Not sure why what you are trying wouldn't work, but it my be worth trying a work around.
Best of luck,
BZ