It’s not dangerous in this case, if $tmpdir was unset, all that would happen is rm -r $tempdir complaining about a missing operand. The only issue I can see this causing is that if mktemp -d fails rm would print an unhelpful error message. Using rm -rf instead would hide it, so could could checking the variable and conditionally running rm -r, as you suggested.
It’s not dangerous in this case, if $tmpdir was unset, all that would happen is
rm -r $tempdircomplaining about a missing operand. The only issue I can see this causing is that ifmktemp -dfailsrmwould print an unhelpful error message. Usingrm -rfinstead would hide it, so could could checking the variable and conditionally runningrm -r, as you suggested.