I think it's best not to assume the worst, since there's a good chance what happened is the unscientific nature of the peer-review process manifesting itself. For example, it's conceivable that the two papers were handled by different members of the editorial board who were not acting in consultation, and one felt the topic was out of scope while the other didn't.
Taking 9 months to decide a paper is out of scope is terrible. However it's also conceivable that they received some confidential (or very poor quality) reviews that they can't share and think the best thing to do is say that your paper is out of scope. This would explain why the decision was "revise and resubmit" for a brief time. There's no way of knowing unfortunately.
What to do now:
1) Next time, if a paper goes more than a month with no sign of review, I suggest emailing the journal office and ask for a status update. It's possible the paper got lost in the system, or simply wasn't submitted correctly. One month should be enough for the journal office to say something, e.g. "we've invited three reviewers of which one has agreed to review, the review is due in 16 days".
2) You can lodge a complaint to either the publisher or the editor-in-chief. It depends on who the editor that rejected your paper is. If that editor is an employee of the publisher, then I would complain to the publisher. Be sure to emphasize that taking 9 months is unreasonable. If it's a member of the editorial board, then I'd approach the EiC, since the publisher is likely to defer to the EiC. If it's the EiC, then there's no point complaining.
3) Submit the paper to another journal. I wouldn't tell them that the paper was rejected at the first journal, unless they ask. You gain nothing by doing so, but could trigger subconscious biases ("we have no idea what to do with this paper, but since the other journal rejected this paper I'll agree with their editor").
4) If you've been scooped, my first inclination would be to complain to the employer of the editor who scooped you, but I genuinely don't know if that's a good idea.