A lens is an optical device - and its performance is what it is. Of course it is possible to correct optical problems with electronics. For example Fuji lenses have a lot of vignetting in some cases. but you can not see it if the camera corrects it.
More megapixels means that in theory you can see more details - if a lens has minimal optical flaws the lens makes it more visible. Some write about diffraction as a problem if the sensor has more megapixels. Of course that is nonsense. Diffraction is what it is , but with 40mp it is possible to see it.
Anyway lenses are not producing absolute resolution - high megapixel count is more useful if the lens is closer to perfect. Usually they are not
Of course a better lens is better. But bad lenses stay bad. And in some cases 40mp can be better than 20mp - but when exactly. Of course pixel peeping in important too
I started my electronic ILC. career with Canon 40D about 18 years ago . The quality of the images has been gettin better during the years. Not so much because of the MP amount. New sensors have less noise , high ISO is much better and especially the DR is stellar nowadays. Compared to the "good old days"
The key here is that less noise, better DR, high ISO improvements have been concurrent with increasing mp. It's a win - win situation.
I just had a look of a big print of my old photo made with X-T1 - size is about 80cm x100cm and I can not see the lower MP count is a problem. I think I can make better big prints from my R5 40mp FF images - but the difference is surprisingly ....
Of course FF and 40mp. really shines in low light and contrasty situations - FF files are better than APS C - I think it is because the sensor is larger and pixel size is bigger . But do we really need FF or 40mp or 60 mp - perhaps somebody needs occasionally.
In 2013 I tried Fuji X, but found out that the sensor quality was not good enough for my type of photography. Then in 2018 tried again and found that it had become good enough, and I changed to Fuji X permanently.
So, sort of a Bottom line
nobody can say how much more it is possible to crop if you have 40mp instead of 20mp - it is repeated that "much more" - 5 or 25% ? Is it easy to see the difference ? It is really easy to see how bad lenses look bad... but comparing sensor sizes - how can you do that ? Without instruments...