I’m not entirely sure that the m*******n editor Discourse uses is part of Discourse itself, but here goes: if you hit the “Header” button or Ctrl-H, the editor adds some header syntax in place without the necessary newlines.
In case you aren’t confused yet, a gif is worth a thousand words. The same happens on SE, for what it’s worth, but SE doesn’t actually have an “add header” button in its interface and that makes this feature well hidden there. <!---- also worth noting that SE is m******n exclusive. —>