Keep in mind that CMake is not one of Stack Exchange's supported languages and as such the lang-cmake
hint is invalid here. As noted there, Stack Exchange only supports a subset of Highlight.js's supported languages, to prevent the highlighting script it serves to others from being too large.
This is happening because in October 2024, changes were made to the syntax highlighting behavior for invalid language hints - prior to then, invalid identifiers would trigger an automatic language detection, then it was changed to not highlight at all. The reasoning behind the change is in the question which that post is answering. However, only the server-side renderer was changed; the client-side renderer was not updated to reflect the change. (Stack Exchange uses different renderers for the client-side preview and the server-side post rendering; occasionally there can be differences between both if one's changed while the other isn't.)
Therefore, in the preview, you see highlighting because your invalid identifier is triggering an automatic language detection (old behavior), while in the rendered post you don't see highlighting (new behavior). Looking at the Developer Tools on the preview's code blocks, it seems that your first code block is being recognized as Swift while your second one is being recognized as SCSS.
While the above third link technically does also report this bug (I'd argue that there's also a side-bug in the discrepancy between what's shown in the preview and what's shown in the edited post for unsupported languages), it primarily reports a separate bug, its title only mentions said separate bug, and the internal ticket that gets created upon a question getting the status-review tag only has the title attached, so I'm going to let this stand as a separate report.