What's happening isn't what you think is happening.
The parser creates an empty head element when it sees the <body> start tag, the second <head> start tag is ignored, and the <script> is treated as part of the body element. Try changing the body of the <script> tag to this:
alert(document.currentScript.parentNode);
It alerts "[object HTMLBodyElement]".The behavior is specced out here, if you're curious: https://www.w3.org/TR/html5/syntax.html#parsing-main-afterbo...