Good question. This happens due to a large number of papers to be reviewed within a limited time frame. Moreover, it depends on the number of reviewers and their area of specialization. For example, some journals ask three reviewers to review your paper within 3 months, If they finished reviewing your paper before that time, the editor will contact you and give you their feedback. Also, I think after this period, you will get a useful feedback which will enhance/improve your paper quality.
It depends upon the particular journal in which the manuscript is submitted. Leading journals maintain a good database of reviewers for each research area and give only limited time to review. One can expect review output within 15-40 days. Other journals may not have a good database of reviewers and it takes time for the editor to find appropriate reviewer and get his nod for review. Nevertheless, there are journals which often send review report only after four months which is their nature or policy. Sometimes, reviewer also may take more than couple of months to comment on the manuscript.
Each and every journal has certain gap between the publication of next issues where the previously submitted manuscripts by authors would be in a queue for publication. So if you submit within that period your article publication will take time. Also, as Dinaharan sir said, the leading journal would publish the articles faster as most of them publish nearly 8-10 issues per year. Therefore, try to publish quality work in leading journals for faster publication.
The submitted manuscripts have to undergo a peer-review process wherein these manuscripts are sent to reviewers for their review and suggestions. This process takes time.