I have the same issue so I think it must be a bug with the forums. The workaround I use to make my code look correct is to edit my post immediately after posting it. You evidently have so long to edit a post after submitting it before it’s locked and no changes can be made to it. Saving the post again after selecting edit without having to make any other changes makes my code look correct.
The first post in this thread is an example of the issue I typically have where you end up with more than one block of code and a lot of extra spacing for the same set of code tags in a post.