I compared the specs of some cameras.
The Canon EOS 5DS and the EOS-1D X MARK II each has a full-frame sensor. The second is more expensive. Their pixel counts are 8868 x 5792 and 5472 x 3648.
Nikon does the same. The the D810 and the D5 each has a full-frame sensor. The second is more expensive. Their pixel counts are 7360 x 4912 and 5568 x 3712.
Why does a more expensive camera have fewer pixels?
By searching, I found some possible explanations, but they are not convincing.
Having fewer pixels means faster processing. I know that more pixels mean slower processing. But I guess processing the picture is very parallel. So with the added price, the manufactures can afford putting in more circuitry. Even if the processing power can't keep up with the increased pixel count, the camera can be programmed to reduce the pixel count for processing by summing 4 pixels into 1 so less processing power is needed. But it still has more pixels when not shooting in burst mode.
Having fewer pixels makes a higher ISO setting possible. With the same sensor size and more pixels on a sensor, the amount of light reaching each pixel will decrease. So the higher pixel count hinders high ISO setting. But a sensor with more pixels won't need as high ISO setting. Say sensor A and sensor B have the same size and resolution. (Let's use the word "resolution" here to mean the resolution of the amount of light that reaches each pixel for example 14 bits on the D810.) Sensor B has 4 times as many pixels. With the help of a microlens in front of each pixel, light lost due to not hitting any pixel is negligible. A takes a picture with the appropriate ISO setting. B takes the same picture with a quarter of that ISO setting. Then the 2 most significant bits of B will be 0. So B's actual resolution will be 2 bits less. But if we only need as many pixels as A has, we can sum 4 pixels of B into 1. (I'm a little stuck as I don't know whether it's only for cost that the highest ISO setting of the D810 is so much lower than that of the D5 scaled inversely proportional to the pixel count.)
Many pixels are for marketing. People tend to only choose a camera based on its pixel count. It may apply when comparing between smartphones and serious cameras. But the said cameras are all for serious people. So it's useless to give the EOS 5DS and D810 more pixels to attract silly people. More pixels allow a photographer to take a clear photograph when there is no time to zoom. If a photographer who uses the D810 may need 36 megapixels, a photographer who uses the D5 may also need them.
Having fewer pixels means less shot noise. The signal-to-noise ratio of shot noise is proportional to the square root of the expected amount of light to arrive each pixel which is inversely proportional to the size of each pixel. But the output from the pixels can be combined to get a picture with fewer pixels and less shot noise.
I've read Why would a more expensive camera have lower megapixels?, but I still don't know.
edit
Why does the Canon 1D X MK 2 only have 20.2MP seems to be asking something alike, but I still don't understand after having read its answers. I don't understand these points in Michael Clark's answer:
All pixels are not equal Each of the said cameras have a full-frame sensor. Increasing the pixel count may make each pixel capture less light, but more pixels give the ability to combine nearby pixels. See the second and forth points above.
Data rates See my first point.
Power consumption A photographer can always set the camera to take pictures with fewer pixels. That is if the increased power consumption is significant. And there are shutter and focus whose power consumption doesn't change as pixels are added.
End use of the images produced If a user of the D810 may need that pixel count, a user of the D5 may also need that pixel count.
Pixels aren't the only distinguishing features of top end cameras But it doesn't explain why a more expensive camera has fewer pixels than another high-end camera.