What are merits of having a PhD degree? What are the benefits of having a PhD degree? Why are PhD programs so competitive? I mean, why do many people apply for PhD programs? 

In STEM fields, it is usually possible to get a better-paid job in industry with a bachelor's or master's degree. On the other hand, PhD programs are usually long, hard and low-paying — if there is any paying at all — and job prospects for PhD graduates are not that impressive too. So, what am I missing? Why do so many talented people try to get into PhD programs if they can get better jobs outside academia? Is it merely because of personal interest in research, teaching or learning? 

Although opinions are important, I sincerely appreciate it if facts and experiences are shared. I agree that this question can be opinion-based but one of the reasons why I am asking this is that choosing to do a PhD degree and possibly pursuing an academic career is a very important decision. Based on personal experience, I have seen many fresh graduates who face the same question (and also a few people that, first, made a decision then faced the question, only to realize that it is late) and I hope that, apart from satiating my personal curiosity, it will provide factual and helpful information for those who have not made their minds yet.
You are asking why people might choose a doctoral candidacy over a better-paying job in the industry.
The straightforward answer is that - at least to the respective people - other factors are given more weight than achieving a maximum in payment alone.
These other factors can include:


freedom in choice of tasks
flexibility in working style
ownership of what you work on
autonomy in collaboration with internal and external partners
authority to draw further people in to your tasks
your colleagues are probably there because they're enthusiastic about what they're doing, not just because they want some job with an acceptable salary
your organisation probably covers a wide range of topics, and any acquisition of knowledge within (or sometimes even outsode of) your organisation can be reasonably counted as working time


Evidently, various of these aspects depend a bit on the concrete situation a doctoraĺ candidacy takes place in.

Lastly, even a payment angle can play into it: I consider it a significant advantage that during the time of my doctoral candidacy (this being a government-funded job), I used to be paid based upon a salary table with automatic raises rather than having to negotiate for any amount of money.