@qnach
I wrote an
Insights Article on Peer Review a while ago that might help you understand the process.
It's important to remember that a journal editor (or associate editor) is not ethically bound to send out all submissions for peer review. While their policy may state something along the lines of "all papers are referred" there should also be a caveat in there somewhere that prior to referral the manuscript needs to meet a certain set of standards: the topic must be appropriate for the journal's scope and target audience, the format needs to conform with the journal's guidelines, the language needs to be clear and coherent, etc.
Remember that the reviewers are volunteers. If a paper clearly does not meet the journal's standards, sending it out to them is a waste of everyone's time. Further, it risks damaging the relationship of the journal with the reviewers as they won't want to volunteer their time for something that should have been stopped before it got to them. If the paper falls outside the journal's scope, the associate editor may not be able to find anyone appropriate to refer the paper to, and it would be a disservice both to the referees and to the authors if they were try to reach outside of their field.
All of that said, I know it's not a great feeling to have your work come back rejected. If you're having a hard time, perhaps you should meet with your supervisor if you're a graduate student, or other people who work in your field if you're a post-doc, and solicit some honest feedback.