Almost everyone addressed the fact that Dubai is a hub for Emirates (and Qantas for their Asia operations) and a large portion of this traffic is transit passengers.
Dubai itself is a large and vibrant metropolis, and that drives a lot of traffic to the area; it holds a lot of the world's first/largest/biggest - starting with Burj Khalifa and its surrounding areas (for example, Ferrari World in Abu Dhabi has the fastest roller coaster) etc. This also helps bring in traffic.
It also helps that politically Dubai and the UAE are relatively stable areas.
Dubai is a regional shopping megacity. Each year there is the Dubai Summer Surprises and the Dubai Shopping Festival; but I would like to address the other valid points in your post:
Riyadh has more than double the population of Dubai, and Saudi Arabia
has triple the population of the UAE, yet Riyadh Airport, despite
being very close to Dubai, is not in even in the top 30.
Specifically for Riyadh and other large airports in Saudi Arabia like Jeddah and Dammam; the reason these large airports have so few passenger numbers is because Saudi Arabia is notoriously difficult to get visas for. Compare this with Dubai that has visa on arrival, e-gate for multiple nationalities and visa applications available online, it makes it easier to stop over in the Emirate, further increasing its appeal.
There is a significant amount of local air traffic (and Saudi Arabia has private airlines as well, like Flynas) - but due to a lack of tourism initiatives and those being restricted to GCC citizens, it reduces the passenger numbers going through these areas (it does help that transit is still a no-visa required situation in Saudi Arabia, but the local incumbent has very few transit flights).
Save for religious travel, like during the annual Hajj passenger traffic is barely a blip on the radar.
In other areas in the Middle East like Bahrain (which also has very liberal visa policies), there simply isn't enough of a draw to bring in passengers. Bahrain's flag carrier Gulf Air (which used be the national airline for Bahrain, Qatar, Abu Dhabi and Oman) is going through an overhaul to modernize its operations, management and fleet.
Qatar however is aggressively expanding its travel capabilities with the expansion of its main airport and Qatar Airways being the first carrier to fly the 787. It is very aggressive in going after Emirates/Etihad especially on the profitable European long-haul and Asian routes - it also competes with Emirates for sponsorship deals.
Locally, you see plenty of competitive pricing between the two.