Is it really legal to submit a work to a venue although we already uploaded it as a reprint somewhere like Arxiv or researchgate?
The answer is simple: those same journals have an explicit exception for preprint servers.
Consider, for example, the Nature family of journals, whose current preprint policy says, in part:

Posting of preprints is not considered prior publication and will not jeopardize consideration at Nature Research journals. Manuscripts posted on preprint servers will not be taken into account when determining the advance provided by a study under consideration at a Nature Research journal.

If you are wondering about a particular journal, the Sherpa/Romeo database is a good information source and often easier than searching the journal's own pages for the applicable policy.