As the comments note, this is a floating point precision issue. In fact both of the examples you show are not precisely equal as evaluated:
> pf(5, 2, 40, lower.tail=F) - (1-pf(5, 2, 40))
[1] 6.245005e-17
> pf(100, 2, 40, lower.tail=F) - (1-pf(500, 2, 40))
[1] 2.735111e-16
It's just that this difference is only apparent in your output for the much smaller number.