Digital cameras capture images as tile-like picture elements known as pixels.
One megapixel equals to one million pixels. Since pixels are usually square and form a grid, a 1-megapixel camera will produce an image roughly 1200 pixels wide by 900 pixels high.
The more the pixels, the image will have a higher resolution, which would translate to more details and better clarity. This should be useful mostly when people want to zoom in or crop a photo. Because the higher the megapixels, more data is packed into it, allowing users to zoom in to the image without seeing much quality loss.
This is even possible for images taken by digital zoom and not optical zoom lenses.
But does the fact remains relevant considering that digital imagery has came a long way?
Then there is the question: does megapixels remains relevant in creating a good picture?

To understand this, let's look into how digital cameras work:
First of all, light rays need to travel and reach the lenses, which direct the light into the sensor. Second, the sensor surface needs to be divided into into one for every pixel, meaning that the larger the sensor, the more megapixels it has, and the smaller the area can be assigned to every pixel. And third, the sensor then converts the light into electrical signals, which are digitized by the software by assigning a color to every pixel
What this means, the better the lenses, the higher their precision to direct light into every part of the sensor, making a more detailed picture with less contaminated pixels.
So here, there are factors that contribute to how good an image will be.
Besides camera lenses and sensor, there are the processor that is responsible for processing the image and manipulating it to fill in the gaps the hardware aren't capable of. Then there are other elements too, like good lighting, proper focus and exposure, shutter speed, camera settings, and others.
Another way of saying this: megapixels matter, but they don't show the bigger picture.
Back in the early days of digital cameras, ‘megapixel war’ was the time when manufacturers raced to create the highest megapixel count on their products. At that time, they marketed the term "megapixels" as some kind of numerical signifier to represent the quality of images their products can take.
But again, that was the time when computational photography hasn't rewritten the rulebook of image processing.
At that time, a camera capable of taking 1 megapixel image was seen as a huge bump over VGA. At that time, the hardware that work alongside the lenses, weren't as sophisticated as they are now at the modern world of technology. There weren't any AIs, or other software-based techniques that were capable of complex image manipulation.
In other words, the most important factor in digital camera quality was purely based on hardware.
Fast forward, smartphones have embedded not only megapixels, but have ventured to go beyond that to over 100 megapixels. Clarity? Yes. Absolute requirement? Not necessary.

Why Megapixels Count Shouldn't Matter For Most People
Just like previously stated, picture quality is based on many factors and elements.
This is why manufacturers that market their digital cameras with high megapixels also ramp up their efforts in improving almost everything else that comes with their cameras.
For example, manufacturers have slowly increased the sensor size of their products. If compared to those days where megapixel cameras were first introduced, modern days cameras have significantly wider lens diameter. The reason for a wide lens is to capture as much data as possible. This way, the cameras should be able to have greater light-gathering powers.
The classic analogy is to imagine a sensor’s millions of photoreceptors (the pixels) as buckets, and light photons as rain falling into them.
The larger the bucket, the stronger the image signal, allowing the camera's other hardware and software to have lesser work to do. Less tampering to the image means that the resulting image will have less noise and higher dynamic range. This is called the 'megapixel conundrum', which crams lots of smaller buckets onto a sensor, and the images will have more pixels that’ll potentially create a sharper image.
Because there is that limit that the bucket can hold, there is also a technique called 'pixel binning', which uses software to cleverly group several pixels together into one bigger pixel. This method allows support for better low-light photography.
On paper, cameras with high megapixels should be more capable of taking clearer and better pictures. But in the real world, photo quality is a result of pixel count, and a lot of other ingredients and flavors, that work together to make a picture a masterpiece.
Megapixels is just a one of the many that contributes to a picture's quality.
It doesn't take math to create an outstanding picture; It's more like a matter of delicate balance of the ingredients that don't overwhelm one another, and instead work together in tandem.