Both sets of HTML are invalid and the browser is performing error recovery. The recovery rules (or rather, the general parser rules) for a span inside a table element are different to the recovery rules for a th inside a table element.
(To oversimplify, a th element has to be inside a tr inside a tbody/tfoot/thead inside a table … so the missing elements are added, but a span doesn't have to be inside a table at all so is thrown out).
You should just write valid HTML from the outset.