Never mind the requests for details, I found a matching bug, CR 777296 "A 940 error, "Dbtable in wrong state for operation: <name>", is reported against tempdb when repeating a query which uses work table for more than 32k times."
It is fixed in 15.7 SP136 and 16.0 SP02 PL02
-bret