If your phone dims 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. Coming back to sunlight, 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 screen will dim a few seconds before the phone locks as a warning. You can wake it by tapping anywhere on the screen.