I just found out that when comments are added in the XML file (or, more specifically, if parts of the XML file are commented to test something), they are removed after the user changes to the editor view and back to the XML view.
Absolutely. This is entirely intentional.

You cannot add
anything to the XML that is not explicitly defined in the .xsd XML schema file included with every project (in HMXZ files it is inside the .hmxz, which is actually a zip). As you have discovered, it will just be removed silently.
XML may look a little like HTML but it is a completely different language. Actually, it is not a language at all, it is a method for defining languages of your own, and the HM XML language ("schema") is defined in the .xsd file. The benefit of XML is that it is 100% strict and error-intolerant. Even a single deviation from the defined syntax will make the entire file invalid. This is necessary because it needs to be absolutely dependable and known for HM to be able to use it as source for publishing to multiple formats.
There is a comment syntax that you can use. Just use the comment tool in Write > Insert Object, then have a look at the resulting XML. For full details, Help & Manual XML format is fully documented in the
Helpman_XML_ref.chm file, which you can find in the Help & Manual program directory.