Is it okay to talk to the editor about the topic of paper or whether if our manuscript is suitable for the journal before submitting?
To give you some context, out of my 13 journal papers I asked the editor twice. Once it was a regular issue, once it was a special issue. Once the paper in question was accepted afterwards, once it was rejected and landed elsewhere.
I wrote typically something along the lines of:

Dear %editor_name%,
I am considering to submit my paper &quot;On the sepulation in the context of the Mars phase&quot; for possible publication in your &quot;International Journal of Highly Reputable Research&quot;. In this manuscript I exploit the stigma of sepulation in the context of the planetary movement. Specially, the Mars phases were never before regarded in this context.
The abstract of my paper is: %abstract in full%
My article contains 4123 words (including footnotes, references and figure captions). It contains 5 color figures and 23 references. I have never published this article before nor have I submitted it to any other journal or conference.
Would such an article be of interest for your journal? Please let me know if you feel that my focus on Mars phases would pose a problem for acceptance in your journal.
Thank you very much. I am looking forward to hearing from you.

Hope this helps.
I have never perceived such queries as bad or damaging. But in most cases they are not needed, as you can tell the relation of your paper to the journal well enough from the aims and scope.
It's the intersection of the actual journal topic with something else, when you might want to ask the editor beforehand.