It’s really interesting when you look at the physics of it.
There are three parts to an equation governing the speed of a bike and rider.
1st part is rolling resistance/drivetrain losses (these are pretty negligible if bike is set up well and tyres pumped up properly).
2nd is air resistance which is squared with velocity and above 15mph becomes the governing factor exponentially
3rd is working against gravity, which on the flat is non existant.
All three elements get added together.
As a result-
Bigger power output generally goes fastest on flat (although different riders in different positions can have slight different drag co-efficients, hence why tt bikes are quicker at speeds) but as a rule, more power output = fastest rider on flat.
When going uphill the steeper it gets the more the gravitational part becomes the governing factor and power to weight becomes way more important than outright power.
I personally like climbs where you sit at about 16mph, it seems to be where my outright power and power to weight work best against other riders as I’m not a racing whippet but am reasonably light and have some power, but not as much as the big guys, slight air resistance getting involved as well as power to weight.