I wonder why editors sometimes do reject submitted manuscripts for being out of the journal's scopes while the authors have utilized published papers from the same journals.
Is it just a polite way of rejection?
Cape Code has given a good answer, but it's not the only possibility for such a rejection. Suppose you publish a paper in, say, "Topology and Its Applications", in which you prove some topological result using (among other things) a set-theoretic lemma. And suppose I later prove some result in algebra using (among other things) your lemma. Of course, I would cite your paper, but that doesn't put my algebra paper into the scope of "Topology and Its Applications".
Citing articles form a given journal does not automatically mean your paper is in its scope.
Even if the subject and methodology of your work seem similar to the ones of the articles in a given journal, the scope can also include quality criteria. As an example, Nature Chemistry, in the description of its scope says:
Nature Chemistry is committed to publishing top-tier original research in all areas of chemistry [...]
Or, some journals decide to accept only papers based on their impact potential. If we look at the New England Journal of Medicine, the scope description states:
We are interested in original research that will change clinical practice or teach us something new about the biology of disease.
One of the most common cases for being out of scope for the journal in such a case is that the paper is not at the right level of the theory-practice scale.
In particular, an application paper can make use of a lot of concepts of earlier theoretical work. Yet, that doesn't meant that the application paper is in scope. If the readership of the journal most likely does not understand the details of the application that are needed to understand the paper, then this is a good reason for rejection.
Likewise, for a theory paper, the problem studied may be well-motivated by practice. Yet, if the novel result builds on concepts that are out-of-scope for the rather practical journal, then the paper is also likely to be rejected.
I'll add another example to the several already given. There are a number of journals (e.g. some or many of the Letters on...) which have a somewhat fast review process, in order to publish results on "hot topics" in a relatively short time.
However, to publish in those kind of journals, not only does your work have to be on-topic, original, innovative, etc. (the usual stuff), but you should also justify the need for such a fast publication track.
Now, even if you produce an original high-quality work with the aim of publishing in such a journal, and even if your paper is apparently within its scope (and even citing references from that same journal), you might have worked on a topic which was hot ten years ago but now barely warm, and your paper would definitely fall out of scope.