If your phone dims in direct sunlight there are a couple of things to check:
If the phone is in direct sunlight it can get very hot, so hot that it is in danger of shutting down if the phone detects it is overheating. So iOS will dim the screen to reduce the amount of heat generated by the screen. If you move the phone to the shade, or shade it with your body, that will usually solve the problem.
One setting to check is Settings/Face ID & Passcode/Attention Aware Features. If this is enabled when you are not looking at the phone (that is, the phone can’t see your eyes) it will dim the screen. If you are in the sun you are probably wearing sun glasses, so the phone can’t see your eyes and it will dim the screen.
Finally, the phone will dim the screen a few seconds before the phone goes to sleep, as a warning. If this is the cause just tapping the screen will stop the shutdown.