The example below shows how if temp_file is made local as part of the same line that mktemp is called then the exit status retrieved using
local is a command itself, not just a modifier to an assignment statement. In test1, you are recording the exit status of the local command, not the command in the command substitution. In test2, you've separated the local command from the assignment to the variable marked as local, so $? contains the exit status you are expecting.
Unrelated, but you don't need to initialize a variable when marking it as local. This works just fine:
local temp_file
temp_file=$(mktemp_xyz -q -t "test.tmp.XXXXXX")
temp_file remains unset until you actually assign a value to it, but the name is local once you actually do assign a value.