It won't hurt anything -- many, many people left their phone to charge all night every night for years before the optimized option was made available.
Note that after you turn the optimize option on, it takes awhile for the iPhone to learn when you normally unplug your phone in the morning. While it is learning, it will charge to 100% rather than 80%. See the information in About Optimized Battery Charging on your iPhone - Apple Support including the following:
When the feature is enabled, your iPhone will delay charging past 80% in certain situations. Your iPhone uses on-device machine learning to learn your daily charging routine so that Optimized Battery Charging activates only when your iPhone predicts it will be connected to a charger for an extended period of time. The algorithm aims to ensure that your iPhone is still fully charged when unplugged.