Hi Szabolcs!
Thanks for the report. I understand the issue, and it’s not strictly a Discourse bug. Discourse uses markdown-it, and this is its standard behavior.
You can see the same behavior on the official demo: https://markdown-it.github.io.
If you need spaces not to be collapsed between backticks, you can add this CSS to your forum:
code {
white-space: pre-wrap;
}