Yeah, this is not a bug, this is the common mark spec
When mixing and matching HTML and markdown you need an extra newline.
This monster works with no newlines, but I would recommend just using the BBCode that @Heliosurge suggested.
<details>
<pre>
<code># yes code
</pre>
</code>
</details>