The same escaped code fragment through both pipeline orders: unescaping first re-creates a bare < that the tag-stripping regex then swallows as markup; stripping tags first leaves the entities untouched, and a single unescape at the end yields the intact code.
Debugging

Unescape HTML entities last, or a tag-stripping regex eats your code

My HTML-to-text viewer showed code blocks truncated at every <. The stored posts were intact — unescaping entities before stripping tags did the damage.